@dialstack/sdk-react 3.7.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-agent.cjs +1 -1
- package/dist/ai-agent.cjs.map +1 -1
- package/dist/ai-agent.d.cts +4 -4
- package/dist/ai-agent.d.ts +4 -4
- package/dist/ai-agent.mjs +1 -1
- package/dist/ai-agent.mjs.map +1 -1
- package/dist/call-history.cjs +1 -1
- package/dist/call-history.cjs.map +1 -1
- package/dist/call-history.mjs +1 -1
- package/dist/call-history.mjs.map +1 -1
- package/dist/call-logs.cjs +1 -1
- package/dist/call-logs.cjs.map +1 -1
- package/dist/call-logs.d.cts +15 -1
- package/dist/call-logs.d.ts +15 -1
- package/dist/call-logs.mjs +1 -1
- package/dist/call-logs.mjs.map +1 -1
- package/dist/dial-plan.cjs +1 -1
- package/dist/dial-plan.cjs.map +1 -1
- package/dist/dial-plan.mjs +1 -1
- package/dist/dial-plan.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -3
- package/dist/index.d.ts +37 -3
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/onboarding.cjs +1 -1
- package/dist/onboarding.cjs.map +1 -1
- package/dist/onboarding.mjs +1 -1
- package/dist/onboarding.mjs.map +1 -1
- package/dist/phone-number-ordering.cjs +1 -1
- package/dist/phone-number-ordering.cjs.map +1 -1
- package/dist/phone-number-ordering.d.cts +11 -5
- package/dist/phone-number-ordering.d.ts +11 -5
- package/dist/phone-number-ordering.mjs +1 -1
- package/dist/phone-number-ordering.mjs.map +1 -1
- package/dist/phone-numbers.cjs +1 -1
- package/dist/phone-numbers.cjs.map +1 -1
- package/dist/phone-numbers.mjs +1 -1
- package/dist/phone-numbers.mjs.map +1 -1
- package/dist/softphone.cjs +1 -1
- package/dist/softphone.cjs.map +1 -1
- package/dist/softphone.d.cts +102 -25
- package/dist/softphone.d.ts +102 -25
- package/dist/softphone.mjs +1 -1
- package/dist/softphone.mjs.map +1 -1
- package/dist/voicemails.cjs +1 -1
- package/dist/voicemails.cjs.map +1 -1
- package/dist/voicemails.d.cts +4 -0
- package/dist/voicemails.d.ts +4 -0
- package/dist/voicemails.mjs +1 -1
- package/dist/voicemails.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react");const t=e.createContext(null),
|
|
1
|
+
"use strict";var e=require("react");const t=e.createContext(null),n=()=>{const n=e.useContext(t);if(!n)throw new Error("Could not find DialStack context; You need to wrap your app in a <DialstackComponentsProvider> provider. See https://docs.dialstack.ai/sdks/setup for setup instructions.");return n};function r(e,t,n,r,o=!1){if(!t)return;const a=e.current,s=null!==a&&a.component===t;if(void 0===n){if(!o||!s||void 0===a.value)return}else if(s&&Object.is(a.value,n))return;e.current={component:t,value:n};try{r(t,n)}catch(e){console.error("DialStack: Error calling setter:",e)}}exports.DialstackComponentsContext=t,exports.DialstackComponentsProvider=({dialstack:n,children:r})=>{var o;null===(o=null==n?void 0:n.registerClientPackage)||void 0===o||o.call(n,"sdk-react","3.9.0");const a={dialstack:n};return e.createElement(t.Provider,{value:a},r)},exports.useAppearance=function(t){const[n,r]=e.useState(()=>t.getAppearance());return e.useEffect(()=>{if("undefined"==typeof document)return;const e=document.createElement("div"),n=e=>{const t=e.detail;r(null==t?void 0:t.appearance)};return e.addEventListener("dialstack-appearance-update",n),t.addAppearanceTarget(e),()=>{t.removeAppearanceTarget(e),e.removeEventListener("dialstack-appearance-update",n)}},[t]),n},exports.useCreateComponent=function(t,n,r){const o=e.useRef(null),a=e.useRef(r);e.useLayoutEffect(()=>{a.current=r});const[s,c]=e.useState(null);return{containerRef:e.useCallback(e=>{var r;if(o.current&&o.current.parentNode&&(o.current.parentNode.removeChild(o.current),o.current=null,c(null)),!e)return;const s=t.create(n);try{!function(e,t){if(!e||"function"!=typeof e.setInstance)throw new Error(`<dialstack-${t}> was created but is not a registered custom element, so it would render nothing. Install @dialstack/sdk-js alongside @dialstack/sdk-react and import it once at your entry point — importing it is what registers the elements. On @dialstack/sdk-js/pure nothing registers on import: await registerComponents() before rendering. If it is installed, check that your bundler is not dropping its side effects.`)}(s,n)}catch(e){throw t.removeAppearanceTarget(s),e}null===(r=a.current)||void 0===r||r.call(a,s),e.appendChild(s),o.current=s,c(s)},[t,n]),componentInstance:s}},exports.useDialstack=()=>{const{dialstack:e}=n();return e},exports.useDialstackComponents=n,exports.useReportComponent=function(n){var r,o,a;null===(a=null===(o=null===(r=e.useContext(t))||void 0===r?void 0:r.dialstack)||void 0===o?void 0:o.registerClientComponent)||void 0===a||a.call(o,"sdk-react",n)},exports.useUpdateHandlerWithSetter=function(t,n,o){const a=e.useRef(null);e.useEffect(()=>r(a,t,n,o,!0))},exports.useUpdateWithSetter=function(t,n,o){const a=e.useRef(null);e.useEffect(()=>r(a,t,n,o))};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/react/
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/react/version.ts","../src/react/DialstackComponentsProvider.tsx","../src/react/useUpdateWithSetter.ts","../src/react/useAppearance.ts","../src/react/useCreateComponent.tsx"],"sourcesContent":[null,null,null,null,null],"names":["DialstackComponentsContext","createContext","useDialstackComponents","context","useContext","Error","applyIfChanged","applied","component","value","onUpdated","clearOnRemove","last","current","sameComponent","undefined","Object","is","error","console","DialstackComponentsProvider","dialstack","children","_a","registerClientPackage","call","React","createElement","Provider","appearance","setAppearance","useState","getAppearance","useEffect","document","target","handler","event","detail","addEventListener","addAppearanceTarget","removeAppearanceTarget","removeEventListener","tagName","beforeAttach","componentRef","useRef","beforeAttachRef","useLayoutEffect","componentInstance","setComponentInstance","containerRef","useCallback","container","parentNode","removeChild","create","element","setInstance","assertUp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B,MAG1Cb,EAAAA,UAAU,IAAM3B,EAAeC,EAASC,EAAWC,EAAOC,GAC5D"}
|
package/dist/index.d.cts
CHANGED
|
@@ -60,6 +60,14 @@ declare const useDialstackComponents: () => DialstackComponentsContextValue;
|
|
|
60
60
|
* @throws {Error} If used outside of DialstackComponentsProvider
|
|
61
61
|
*/
|
|
62
62
|
declare const useDialstack: () => DialStackInstance;
|
|
63
|
+
/**
|
|
64
|
+
* Report a React-only component (one that is not a web component, which
|
|
65
|
+
* reports itself) in the `DialStack-Client` header. No-op outside a provider.
|
|
66
|
+
* Runs during render, like the provider's own registration, so requests from
|
|
67
|
+
* the component's children's mount effects already carry it.
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
declare function useReportComponent(name: string): void;
|
|
63
71
|
|
|
64
72
|
/**
|
|
65
73
|
* React hook for creating and managing Web Components
|
|
@@ -91,7 +99,14 @@ interface UseCreateComponentResult<T extends ComponentTagName> {
|
|
|
91
99
|
* // TypeScript knows about setUserId, setOnVoicemailPlay, etc.
|
|
92
100
|
* ```
|
|
93
101
|
*/
|
|
94
|
-
declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialStackInstance, tagName: T
|
|
102
|
+
declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialStackInstance, tagName: T,
|
|
103
|
+
/**
|
|
104
|
+
* Applies props to the element before it is attached. Attaching is what
|
|
105
|
+
* starts its first load, and the prop effects only run after that, so a
|
|
106
|
+
* setting that shapes the first request belongs here or it costs a second
|
|
107
|
+
* one. Read at creation time; it does not re-run.
|
|
108
|
+
*/
|
|
109
|
+
beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResult<T>;
|
|
95
110
|
|
|
96
111
|
/**
|
|
97
112
|
* React hook for synchronizing React props to Web Component setter methods
|
|
@@ -105,6 +120,17 @@ declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialS
|
|
|
105
120
|
* This enables declarative React patterns (props) to control imperative
|
|
106
121
|
* Web Component APIs (setter methods) in a type-safe way.
|
|
107
122
|
*
|
|
123
|
+
* The setter runs only when the component or the value changes, compared by
|
|
124
|
+
* identity like React's own effect deps, so a host that re-renders often
|
|
125
|
+
* doesn't make the element re-render or reload.
|
|
126
|
+
* That makes two things part of the contract:
|
|
127
|
+
* - `onUpdated` must depend only on `component` and `value`. A setter closing
|
|
128
|
+
* over other state isn't re-run when only that state changes; pass it in
|
|
129
|
+
* `value` instead.
|
|
130
|
+
* - Keep object props stable (a constant, `useMemo`, state) and replace rather
|
|
131
|
+
* than mutate them: an inline `{…}` is a new value on every render, and a
|
|
132
|
+
* value mutated in place is the same one.
|
|
133
|
+
*
|
|
108
134
|
* @param component - The Web Component instance (or null if not mounted)
|
|
109
135
|
* @param value - The prop value to sync
|
|
110
136
|
* @param onUpdated - Callback that receives the component and value, should call the setter
|
|
@@ -119,7 +145,8 @@ declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialS
|
|
|
119
145
|
* comp.setUserId(val);
|
|
120
146
|
* });
|
|
121
147
|
*
|
|
122
|
-
*
|
|
148
|
+
* // A callback: removing the prop clears it on the element.
|
|
149
|
+
* useUpdateHandlerWithSetter(componentInstance, onVoicemailSelect, (comp, val) => {
|
|
123
150
|
* comp.setOnVoicemailSelect(val);
|
|
124
151
|
* });
|
|
125
152
|
*
|
|
@@ -128,6 +155,13 @@ declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialS
|
|
|
128
155
|
* ```
|
|
129
156
|
*/
|
|
130
157
|
declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | null, value: V | undefined, onUpdated: (component: T, value: V) => void): void;
|
|
158
|
+
/**
|
|
159
|
+
* `useUpdateWithSetter` for a callback prop: when the host stops passing it,
|
|
160
|
+
* the setter is called once with `undefined`, so the element stops calling a
|
|
161
|
+
* handler the host has let go of. Other props keep their last value instead,
|
|
162
|
+
* since clearing them would need a per-setter reset to defaults.
|
|
163
|
+
*/
|
|
164
|
+
declare function useUpdateHandlerWithSetter<T extends HTMLElement, H>(component: T | null, handler: H | undefined, onUpdated: (component: T, handler: H | undefined) => void): void;
|
|
131
165
|
|
|
132
166
|
/**
|
|
133
167
|
* useAppearance — subscribe to live appearance updates from a DialStack instance.
|
|
@@ -144,5 +178,5 @@ declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | nu
|
|
|
144
178
|
*/
|
|
145
179
|
declare function useAppearance(dialstack: DialStackInstance): AppearanceOptions | undefined;
|
|
146
180
|
|
|
147
|
-
export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useUpdateWithSetter };
|
|
181
|
+
export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useReportComponent, useUpdateHandlerWithSetter, useUpdateWithSetter };
|
|
148
182
|
export type { DialstackComponentsProviderProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,14 @@ declare const useDialstackComponents: () => DialstackComponentsContextValue;
|
|
|
60
60
|
* @throws {Error} If used outside of DialstackComponentsProvider
|
|
61
61
|
*/
|
|
62
62
|
declare const useDialstack: () => DialStackInstance;
|
|
63
|
+
/**
|
|
64
|
+
* Report a React-only component (one that is not a web component, which
|
|
65
|
+
* reports itself) in the `DialStack-Client` header. No-op outside a provider.
|
|
66
|
+
* Runs during render, like the provider's own registration, so requests from
|
|
67
|
+
* the component's children's mount effects already carry it.
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
declare function useReportComponent(name: string): void;
|
|
63
71
|
|
|
64
72
|
/**
|
|
65
73
|
* React hook for creating and managing Web Components
|
|
@@ -91,7 +99,14 @@ interface UseCreateComponentResult<T extends ComponentTagName> {
|
|
|
91
99
|
* // TypeScript knows about setUserId, setOnVoicemailPlay, etc.
|
|
92
100
|
* ```
|
|
93
101
|
*/
|
|
94
|
-
declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialStackInstance, tagName: T
|
|
102
|
+
declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialStackInstance, tagName: T,
|
|
103
|
+
/**
|
|
104
|
+
* Applies props to the element before it is attached. Attaching is what
|
|
105
|
+
* starts its first load, and the prop effects only run after that, so a
|
|
106
|
+
* setting that shapes the first request belongs here or it costs a second
|
|
107
|
+
* one. Read at creation time; it does not re-run.
|
|
108
|
+
*/
|
|
109
|
+
beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResult<T>;
|
|
95
110
|
|
|
96
111
|
/**
|
|
97
112
|
* React hook for synchronizing React props to Web Component setter methods
|
|
@@ -105,6 +120,17 @@ declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialS
|
|
|
105
120
|
* This enables declarative React patterns (props) to control imperative
|
|
106
121
|
* Web Component APIs (setter methods) in a type-safe way.
|
|
107
122
|
*
|
|
123
|
+
* The setter runs only when the component or the value changes, compared by
|
|
124
|
+
* identity like React's own effect deps, so a host that re-renders often
|
|
125
|
+
* doesn't make the element re-render or reload.
|
|
126
|
+
* That makes two things part of the contract:
|
|
127
|
+
* - `onUpdated` must depend only on `component` and `value`. A setter closing
|
|
128
|
+
* over other state isn't re-run when only that state changes; pass it in
|
|
129
|
+
* `value` instead.
|
|
130
|
+
* - Keep object props stable (a constant, `useMemo`, state) and replace rather
|
|
131
|
+
* than mutate them: an inline `{…}` is a new value on every render, and a
|
|
132
|
+
* value mutated in place is the same one.
|
|
133
|
+
*
|
|
108
134
|
* @param component - The Web Component instance (or null if not mounted)
|
|
109
135
|
* @param value - The prop value to sync
|
|
110
136
|
* @param onUpdated - Callback that receives the component and value, should call the setter
|
|
@@ -119,7 +145,8 @@ declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialS
|
|
|
119
145
|
* comp.setUserId(val);
|
|
120
146
|
* });
|
|
121
147
|
*
|
|
122
|
-
*
|
|
148
|
+
* // A callback: removing the prop clears it on the element.
|
|
149
|
+
* useUpdateHandlerWithSetter(componentInstance, onVoicemailSelect, (comp, val) => {
|
|
123
150
|
* comp.setOnVoicemailSelect(val);
|
|
124
151
|
* });
|
|
125
152
|
*
|
|
@@ -128,6 +155,13 @@ declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialS
|
|
|
128
155
|
* ```
|
|
129
156
|
*/
|
|
130
157
|
declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | null, value: V | undefined, onUpdated: (component: T, value: V) => void): void;
|
|
158
|
+
/**
|
|
159
|
+
* `useUpdateWithSetter` for a callback prop: when the host stops passing it,
|
|
160
|
+
* the setter is called once with `undefined`, so the element stops calling a
|
|
161
|
+
* handler the host has let go of. Other props keep their last value instead,
|
|
162
|
+
* since clearing them would need a per-setter reset to defaults.
|
|
163
|
+
*/
|
|
164
|
+
declare function useUpdateHandlerWithSetter<T extends HTMLElement, H>(component: T | null, handler: H | undefined, onUpdated: (component: T, handler: H | undefined) => void): void;
|
|
131
165
|
|
|
132
166
|
/**
|
|
133
167
|
* useAppearance — subscribe to live appearance updates from a DialStack instance.
|
|
@@ -144,5 +178,5 @@ declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | nu
|
|
|
144
178
|
*/
|
|
145
179
|
declare function useAppearance(dialstack: DialStackInstance): AppearanceOptions | undefined;
|
|
146
180
|
|
|
147
|
-
export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useUpdateWithSetter };
|
|
181
|
+
export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useReportComponent, useUpdateHandlerWithSetter, useUpdateWithSetter };
|
|
148
182
|
export type { DialstackComponentsProviderProps };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{createContext as t,useContext as
|
|
1
|
+
import e,{createContext as t,useContext as n,useRef as r,useLayoutEffect as a,useState as o,useCallback as i,useEffect as c}from"react";const l=t(null),s=({dialstack:t,children:n})=>{var r;null===(r=null==t?void 0:t.registerClientPackage)||void 0===r||r.call(t,"sdk-react","3.9.0");const a={dialstack:t};return e.createElement(l.Provider,{value:a},n)},u=()=>{const e=n(l);if(!e)throw new Error("Could not find DialStack context; You need to wrap your app in a <DialstackComponentsProvider> provider. See https://docs.dialstack.ai/sdks/setup for setup instructions.");return e},d=()=>{const{dialstack:e}=u();return e};function p(e){var t,r,a;null===(a=null===(r=null===(t=n(l))||void 0===t?void 0:t.dialstack)||void 0===r?void 0:r.registerClientComponent)||void 0===a||a.call(r,"sdk-react",e)}function v(e,t,n){const c=r(null),l=r(n);a(()=>{l.current=n});const[s,u]=o(null);return{containerRef:i(n=>{var r;if(c.current&&c.current.parentNode&&(c.current.parentNode.removeChild(c.current),c.current=null,u(null)),!n)return;const a=e.create(t);try{!function(e,t){if(!e||"function"!=typeof e.setInstance)throw new Error(`<dialstack-${t}> was created but is not a registered custom element, so it would render nothing. Install @dialstack/sdk-js alongside @dialstack/sdk-react and import it once at your entry point — importing it is what registers the elements. On @dialstack/sdk-js/pure nothing registers on import: await registerComponents() before rendering. If it is installed, check that your bundler is not dropping its side effects.`)}(a,t)}catch(t){throw e.removeAppearanceTarget(a),t}null===(r=l.current)||void 0===r||r.call(l,a),n.appendChild(a),c.current=a,u(a)},[e,t]),componentInstance:s}}function f(e,t,n){const a=r(null);c(()=>m(a,e,t,n))}function k(e,t,n){const a=r(null);c(()=>m(a,e,t,n,!0))}function m(e,t,n,r,a=!1){if(!t)return;const o=e.current,i=null!==o&&o.component===t;if(void 0===n){if(!a||!i||void 0===o.value)return}else if(i&&Object.is(o.value,n))return;e.current={component:t,value:n};try{r(t,n)}catch(e){console.error("DialStack: Error calling setter:",e)}}function g(e){const[t,n]=o(()=>e.getAppearance());return c(()=>{if("undefined"==typeof document)return;const t=document.createElement("div"),r=e=>{const t=e.detail;n(null==t?void 0:t.appearance)};return t.addEventListener("dialstack-appearance-update",r),e.addAppearanceTarget(t),()=>{e.removeAppearanceTarget(t),t.removeEventListener("dialstack-appearance-update",r)}},[e]),t}export{l as DialstackComponentsContext,s as DialstackComponentsProvider,g as useAppearance,v as useCreateComponent,d as useDialstack,u as useDialstackComponents,p as useReportComponent,k as useUpdateHandlerWithSetter,f as useUpdateWithSetter};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/react/
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/react/version.ts","../src/react/DialstackComponentsProvider.tsx","../src/react/useCreateComponent.tsx","../src/react/useUpdateWithSetter.ts","../src/react/useAppearance.ts"],"sourcesContent":[null,null,null,null,null],"names":["DialstackComponentsContext","createContext","DialstackComponentsProvider","dialstack","children","_a","registerClientPackage","call","value","React","createElement","Provider","useDialstackComponents","context","useContext","Error","useDialstack","useReportComponent","name","_c","_b","registerClientComponent","useCreateComponent","tagName","beforeAttach","componentRef","useRef","beforeAttachRef","useLayoutEffect","current","componentInstance","setComponentInstance","useState","containerRef","useCallback","container","parentNode","removeChild","component","create","element","setInstance","assertUpgraded","err","removeAppearanceTarget","appendChild","useUpdateWithSetter","onUpdated","applied","useEffect","applyIfChanged","useUpdateHandlerWithSetter","handler","clearOnRemove","last","sameComponent","undefined","Object","is","error","console","useAppearance","appearance","setAppearance","getAppearance","document","target","event","detail","addEventListener","addAppearanceTarget","removeEventListener"],"mappings":"wIAEO,MCkBDA,EAA6BC,EAAsD,MAkC5EC,EAA0EA,EACrFC,YACAC,qBAOgC,QAAhCC,EAAAF,aAAS,EAATA,EAAWG,6BAAqB,IAAAD,GAAAA,EAAAE,KAAAJ,EAAG,YD7DN,SC+D7B,MAAMK,EAAyC,CAC7CL,aAGF,OACEM,EAAAC,cAACV,EAA2BW,SAAQ,CAACH,MAAOA,GACzCJ,IAUMQ,EAAyBA,KACpC,MAAMC,EAAUC,EAAWd,GAC3B,IAAKa,EACH,MAAM,IAAIE,MACR,6KAIJ,OAAOF,GAQIG,EAAeA,KAC1B,MAAMb,UAAEA,GAAcS,IACtB,OAAOT,GAUH,SAAUc,EAA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