@minihog/nuxt 0.0.0-stage → 0.1.1
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/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/README.md +127 -2
- package/dist/module.d.ts +5 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +92 -0
- package/dist/module.js.map +1 -0
- package/dist/runtime/composable.d.ts +4 -0
- package/dist/runtime/composable.d.ts.map +1 -0
- package/dist/runtime/composable.js +6 -0
- package/dist/runtime/composable.js.map +1 -0
- package/dist/runtime/controller.d.ts +6 -0
- package/dist/runtime/controller.d.ts.map +1 -0
- package/dist/runtime/controller.js +52 -0
- package/dist/runtime/controller.js.map +1 -0
- package/dist/runtime/plugin.d.ts +7 -0
- package/dist/runtime/plugin.d.ts.map +1 -0
- package/dist/runtime/plugin.js +20 -0
- package/dist/runtime/plugin.js.map +1 -0
- package/dist/runtime/server/body.d.ts +4 -0
- package/dist/runtime/server/body.d.ts.map +1 -0
- package/dist/runtime/server/body.js +28 -0
- package/dist/runtime/server/body.js.map +1 -0
- package/dist/runtime/server/proxy.d.ts +3 -0
- package/dist/runtime/server/proxy.d.ts.map +1 -0
- package/dist/runtime/server/proxy.js +62 -0
- package/dist/runtime/server/proxy.js.map +1 -0
- package/dist/runtime/server/routing.d.ts +4 -0
- package/dist/runtime/server/routing.d.ts.map +1 -0
- package/dist/runtime/server/routing.js +18 -0
- package/dist/runtime/server/routing.js.map +1 -0
- package/dist/templates.d.ts +4 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +88 -0
- package/dist/templates.js.map +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +76 -3
- package/src/module.ts +99 -0
- package/src/runtime/composable.ts +7 -0
- package/src/runtime/controller.ts +54 -0
- package/src/runtime/plugin.ts +23 -0
- package/src/runtime/server/body.ts +26 -0
- package/src/runtime/server/proxy.ts +63 -0
- package/src/runtime/server/routing.ts +15 -0
- package/src/shims.d.ts +9 -0
- package/src/templates.ts +91 -0
- package/src/types.ts +59 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @minihog/nuxt
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Core | Nuxt:
|
|
8
|
+
- Updated development tooling, Nuxt integration, and pnpm to 12.25.1.
|
|
9
|
+
|
|
10
|
+
- Updated dependencies []:
|
|
11
|
+
- @minihog/core@0.1.1
|
|
12
|
+
|
|
13
|
+
## 0.1.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- Core | Nuxt:
|
|
18
|
+
- Made the initial release of small, modular PostHog client for modern browsers.
|
|
19
|
+
- Made the initial release of nuxt module for MiniHog with a same-origin PostHog proxy and deferred startup.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Stefan Popov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,128 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @minihog/nuxt
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Nuxt 4 integration for `@minihog/core`. It installs a typed controller, a `useMiniHog()` composable, and an allowlisted same-origin proxy. Feature imports are generated at build time, so disabled features produce no chunks. Enabled replay and web-vitals chunks load only when remote settings allow them.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @minihog/nuxt
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
export default defineNuxtConfig({
|
|
13
|
+
modules: ['@minihog/nuxt'],
|
|
14
|
+
minihog: {
|
|
15
|
+
host: 'https://eu.i.posthog.com',
|
|
16
|
+
proxyPath: '/api/_ph',
|
|
17
|
+
start: 'ready',
|
|
18
|
+
browser: { pageviews: true, autocapture: true }
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Set `NUXT_PUBLIC_MINIHOG_KEY` to the public project token at runtime. `key` in the module options provides a build-time default. An empty key prevents importing the analytics implementation and makes no analytics requests.
|
|
24
|
+
|
|
25
|
+
The default host is US Cloud. EU Cloud automatically uses `eu-assets.i.posthog.com` for JSON configuration. Self-hosted installations can specify `assetsHost` separately. Host values must be HTTP(S) origins; the proxy does not accept a target supplied by a request.
|
|
26
|
+
|
|
27
|
+
## Module options
|
|
28
|
+
|
|
29
|
+
| Option | Default | Purpose |
|
|
30
|
+
| ----------------------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
31
|
+
| `key` | Empty | Public project token, overridable with `NUXT_PUBLIC_MINIHOG_KEY` |
|
|
32
|
+
| `host` | `https://us.i.posthog.com` | Ingestion origin |
|
|
33
|
+
| `assetsHost` | Matching Cloud asset origin, otherwise `host` | JSON project configuration |
|
|
34
|
+
| `proxyPath` | `/api/_ph` | Local server route prefix |
|
|
35
|
+
| `start` | `ready` | Choose `ready`, `idle`, or `manual` |
|
|
36
|
+
| `browser` | `{}` | Pageviews, autocapture, rage clicks, and text capture; `false` disables browser capture |
|
|
37
|
+
| `webVitals`, `heatmaps`, `replay` | `false` | Enable independent feature imports |
|
|
38
|
+
| `consoleRecording`, `networkTiming` | `false` | Add diagnostics to enabled replay |
|
|
39
|
+
| `errorCapture` | `false` | Capture browser errors and unhandled rejections |
|
|
40
|
+
| `client` | `{}` | Serializable persistence, consent, profile, session-timeout, and flush options |
|
|
41
|
+
|
|
42
|
+
The module exports `ModuleOptions` and `MiniHogController` types. Callback functions and custom storage/transports belong in a direct core integration rather than serializable Nuxt runtime configuration.
|
|
43
|
+
|
|
44
|
+
## Delay initialization
|
|
45
|
+
|
|
46
|
+
Set `start: 'manual'` to keep the analytics implementation unloaded until the application calls `start()`:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
export default defineNuxtPlugin({
|
|
50
|
+
name: 'analytics-after-content',
|
|
51
|
+
dependsOn: ['minihog'],
|
|
52
|
+
setup() {
|
|
53
|
+
const analytics = useMiniHog();
|
|
54
|
+
const contentReady = useState<boolean>('content-ready');
|
|
55
|
+
|
|
56
|
+
onNuxtReady(() => {
|
|
57
|
+
const stop = watch(contentReady, (ready) => {
|
|
58
|
+
if (ready) {
|
|
59
|
+
stop();
|
|
60
|
+
void analytics.start();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (contentReady.value) {
|
|
64
|
+
stop();
|
|
65
|
+
void analytics.start();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Start analytics when your application's readiness condition is satisfied. Handle failed initialization of the deferred feature as well, so analytics can still start. Visits and interactions before `start()` are not collected.
|
|
73
|
+
|
|
74
|
+
`start: 'ready'` starts on Nuxt readiness. `start: 'idle'` schedules another browser idle callback with a two-second timeout after Nuxt readiness. Neither mode runs the analytics client during SSR. For a consent-based start, call `start()` after obtaining consent or use `client.optOutByDefault` and explicitly opt in.
|
|
75
|
+
|
|
76
|
+
Use `manual` when expensive rendering has an explicit completion signal; the `idle` timeout can start analytics while the page is busy.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const analytics = useMiniHog();
|
|
80
|
+
await analytics.start();
|
|
81
|
+
analytics.getClient()?.capture('project_opened', { slug: 'example' });
|
|
82
|
+
await analytics.stop();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Concurrent starts share one promise. Stop cancels a pending initialization, cleans up a late client, and permits a later restart. Initialization failure returns `undefined` and logs a warning without preventing page rendering.
|
|
86
|
+
|
|
87
|
+
## Optional features
|
|
88
|
+
|
|
89
|
+
Enable features through module options. Package managers with automatic peer installation resolve the [core package's required peers](https://github.com/stefashkaa/minihog/tree/main/packages/core#install-and-capture); otherwise, add them explicitly.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
export default defineNuxtConfig({
|
|
93
|
+
modules: ['@minihog/nuxt'],
|
|
94
|
+
minihog: {
|
|
95
|
+
webVitals: true,
|
|
96
|
+
heatmaps: true,
|
|
97
|
+
replay: true,
|
|
98
|
+
consoleRecording: true,
|
|
99
|
+
networkTiming: true,
|
|
100
|
+
errorCapture: false,
|
|
101
|
+
client: { personProfiles: 'identified_only', migratePostHog: true }
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
For feature flags, identity helpers, or headless surveys, add `@minihog/core` as a direct dependency and import the corresponding entry point.
|
|
107
|
+
|
|
108
|
+
Remote settings can only enable locally selected features. Unsupported replay targeting/payload rules and enforced heatmap URL rules disable those features and produce a warning.
|
|
109
|
+
|
|
110
|
+
## Proxy behavior
|
|
111
|
+
|
|
112
|
+
The module installs these paths beneath `proxyPath`:
|
|
113
|
+
|
|
114
|
+
| Method | Path | Purpose |
|
|
115
|
+
| ------ | ----------------------- | ----------------------------------------------- |
|
|
116
|
+
| POST | `/batch/`, `/i/v0/e/` | Event ingestion |
|
|
117
|
+
| POST | `/s/` | Replay snapshots |
|
|
118
|
+
| POST | `/flags/` | Flag evaluation; query parameters are preserved |
|
|
119
|
+
| GET | `/array/<token>/config` | JSON configuration from the asset host |
|
|
120
|
+
| GET | `/api/surveys/` | Public survey definitions |
|
|
121
|
+
|
|
122
|
+
Other paths and methods return 404. Cookies and authorization headers are not forwarded. Responses use `no-store`. Requests have a ten-second upstream timeout and a 2 MiB body limit. Apply deployment-specific rate limits at your hosting layer if needed.
|
|
123
|
+
|
|
124
|
+
The module requires Nuxt 4 and a Node-based Nitro server or serverless deployment. A static-only Nuxt export cannot serve the proxy routes.
|
|
125
|
+
|
|
126
|
+
## Contributing
|
|
127
|
+
|
|
128
|
+
See [CONTRIBUTING.md](https://github.com/stefashkaa/minihog/blob/main/CONTRIBUTING.md) for development setup and tests. A complete example is in [`demo`](https://github.com/stefashkaa/minihog/tree/main/demo).
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ModuleOptions } from './types.js';
|
|
2
|
+
export type { MiniHogController, ModuleOptions } from './types.js';
|
|
3
|
+
declare const _default: import("@nuxt/schema").NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
4
|
+
export default _default;
|
|
5
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;;AAEnE,wBA2FG"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { addImports, addPlugin, addServerHandler, addTemplate, createResolver, defineNuxtModule } from '@nuxt/kit';
|
|
2
|
+
import { initializerSource } from './templates.js';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
export default defineNuxtModule({
|
|
5
|
+
meta: { name: '@minihog/nuxt', configKey: 'minihog', compatibility: { nuxt: '^4.0.0' } },
|
|
6
|
+
defaults: {
|
|
7
|
+
key: '',
|
|
8
|
+
host: 'https://us.i.posthog.com',
|
|
9
|
+
proxyPath: '/api/_ph',
|
|
10
|
+
start: 'ready',
|
|
11
|
+
browser: {},
|
|
12
|
+
webVitals: false,
|
|
13
|
+
heatmaps: false,
|
|
14
|
+
replay: false,
|
|
15
|
+
consoleRecording: false,
|
|
16
|
+
networkTiming: false,
|
|
17
|
+
errorCapture: false,
|
|
18
|
+
client: {}
|
|
19
|
+
},
|
|
20
|
+
setup(options, nuxt) {
|
|
21
|
+
const resolver = createResolver(import.meta.url);
|
|
22
|
+
const host = new URL(options.host);
|
|
23
|
+
if (!['http:', 'https:'].includes(host.protocol) ||
|
|
24
|
+
host.username ||
|
|
25
|
+
host.password ||
|
|
26
|
+
host.search ||
|
|
27
|
+
host.hash ||
|
|
28
|
+
host.pathname !== '/') {
|
|
29
|
+
throw new Error('minihog.host must be an HTTP(S) origin without credentials, a path, or query parameters.');
|
|
30
|
+
}
|
|
31
|
+
const path = options.proxyPath.replace(/\/+$/, '');
|
|
32
|
+
if (!/^\/(?:[a-zA-Z0-9_-]+\/)*[a-zA-Z0-9_-]+$/.test(path))
|
|
33
|
+
throw new Error('minihog.proxyPath must be an absolute local path.');
|
|
34
|
+
const assetsHost = options.assetsHost ??
|
|
35
|
+
(host.hostname === 'eu.i.posthog.com'
|
|
36
|
+
? 'https://eu-assets.i.posthog.com'
|
|
37
|
+
: host.hostname === 'us.i.posthog.com'
|
|
38
|
+
? 'https://us-assets.i.posthog.com'
|
|
39
|
+
: host.origin);
|
|
40
|
+
const assets = new URL(assetsHost);
|
|
41
|
+
if (!['http:', 'https:'].includes(assets.protocol) ||
|
|
42
|
+
assets.username ||
|
|
43
|
+
assets.password ||
|
|
44
|
+
assets.search ||
|
|
45
|
+
assets.hash ||
|
|
46
|
+
assets.pathname !== '/')
|
|
47
|
+
throw new Error('minihog.assetsHost must be an HTTP(S) origin.');
|
|
48
|
+
nuxt.options.runtimeConfig.minihog = { host: host.origin, assetsHost: assets.origin, path };
|
|
49
|
+
nuxt.options.runtimeConfig.public.minihog = {
|
|
50
|
+
key: options.key ?? '',
|
|
51
|
+
proxyPath: path,
|
|
52
|
+
start: options.start,
|
|
53
|
+
client: options.client ?? {}
|
|
54
|
+
};
|
|
55
|
+
const template = addTemplate({
|
|
56
|
+
filename: 'minihog/init.mjs',
|
|
57
|
+
getContents: () => initializerSource(options)
|
|
58
|
+
});
|
|
59
|
+
nuxt.options.alias['#minihog-init'] = template.dst;
|
|
60
|
+
// Resolve from the installed module, including when pnpm keeps core transitive.
|
|
61
|
+
// Specific subpaths precede the root because Vite aliases also match prefixes.
|
|
62
|
+
for (const entry of [
|
|
63
|
+
'identity',
|
|
64
|
+
'flags',
|
|
65
|
+
'surveys',
|
|
66
|
+
'package.json',
|
|
67
|
+
'browser',
|
|
68
|
+
'remote-config',
|
|
69
|
+
'web-vitals',
|
|
70
|
+
'heatmaps',
|
|
71
|
+
'replay-console',
|
|
72
|
+
'replay-network',
|
|
73
|
+
'replay',
|
|
74
|
+
'errors',
|
|
75
|
+
''
|
|
76
|
+
]) {
|
|
77
|
+
const specifier = `@minihog/core${entry ? `/${entry}` : ''}`;
|
|
78
|
+
nuxt.options.alias[specifier] = fileURLToPath(import.meta.resolve(specifier));
|
|
79
|
+
}
|
|
80
|
+
addPlugin({ src: resolver.resolve('./runtime/plugin.js'), order: -20 });
|
|
81
|
+
addImports({ name: 'useMiniHog', from: resolver.resolve('./runtime/composable.js') });
|
|
82
|
+
addServerHandler({ route: `${path}/**`, handler: resolver.resolve('./runtime/server/proxy.js') });
|
|
83
|
+
nuxt.hook('build:manifest', (manifest) => {
|
|
84
|
+
// These chunks must follow the application's start() boundary, including replay peers.
|
|
85
|
+
for (const [id, entry] of Object.entries(manifest)) {
|
|
86
|
+
if (/minihog|rrweb|web-vitals/.test(id))
|
|
87
|
+
entry.prefetch = false;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACnH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,eAAe,gBAAgB,CAAgB;IAC7C,IAAI,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IACxF,QAAQ,EAAE;QACR,GAAG,EAAE,EAAE;QACP,IAAI,EAAE,0BAA0B;QAChC,SAAS,EAAE,UAAU;QACrB,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,EAAE;QACX,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,KAAK;QACb,gBAAgB,EAAE,KAAK;QACvB,aAAa,EAAE,KAAK;QACpB,YAAY,EAAE,KAAK;QACnB,MAAM,EAAE,EAAE;KACX;IACD,KAAK,CAAC,OAAO,EAAE,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xE,UAAU,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,yBAAyB,CAAC,EAAE,CAAC,CAAC;QACtF,gBAAgB,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC;QAClG,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,EAAE;YACvC,uFAAuF;YACvF,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACnD,IAAI,0BAA0B,CAAC,IAAI,CAAC,EAAE,CAAC;oBAAE,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC;YAClE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composable.d.ts","sourceRoot":"","sources":["../../src/runtime/composable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,iFAAiF;AACjF,wBAAgB,UAAU,IAAI,iBAAiB,CAE9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composable.js","sourceRoot":"","sources":["../../src/runtime/composable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,iFAAiF;AACjF,MAAM,UAAU,UAAU;IACxB,OAAO,UAAU,EAAE,CAAC,QAAQ,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MiniHog } from '@minihog/core';
|
|
2
|
+
import type { MiniHogController, PublicOptions } from '../types.js';
|
|
3
|
+
type Initialize = (config: PublicOptions, isActive: () => boolean) => Promise<MiniHog>;
|
|
4
|
+
export declare function createController(config: PublicOptions, load: () => Promise<Initialize>, onError: (error: unknown) => void): MiniHogController;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/runtime/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpE,KAAK,UAAU,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEvF,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,EAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,iBAAiB,CA4CnB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function createController(config, load, onError) {
|
|
2
|
+
let client;
|
|
3
|
+
let pending;
|
|
4
|
+
let generation = 0;
|
|
5
|
+
return {
|
|
6
|
+
getClient: () => client,
|
|
7
|
+
start() {
|
|
8
|
+
if (!config.key)
|
|
9
|
+
return Promise.resolve(undefined);
|
|
10
|
+
if (client)
|
|
11
|
+
return Promise.resolve(client);
|
|
12
|
+
if (pending)
|
|
13
|
+
return pending;
|
|
14
|
+
const version = generation;
|
|
15
|
+
const operation = load()
|
|
16
|
+
.then((initialize) => {
|
|
17
|
+
if (version === generation)
|
|
18
|
+
return initialize(config, () => version === generation);
|
|
19
|
+
})
|
|
20
|
+
.then(async (created) => {
|
|
21
|
+
if (!created)
|
|
22
|
+
return;
|
|
23
|
+
if (version !== generation) {
|
|
24
|
+
await created.destroy();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
client = created;
|
|
28
|
+
return client;
|
|
29
|
+
})
|
|
30
|
+
.catch((error) => {
|
|
31
|
+
onError(error);
|
|
32
|
+
return undefined;
|
|
33
|
+
})
|
|
34
|
+
.finally(() => {
|
|
35
|
+
if (pending === operation)
|
|
36
|
+
pending = undefined;
|
|
37
|
+
});
|
|
38
|
+
pending = operation;
|
|
39
|
+
return operation;
|
|
40
|
+
},
|
|
41
|
+
async stop() {
|
|
42
|
+
generation++;
|
|
43
|
+
const loading = pending;
|
|
44
|
+
const previous = client;
|
|
45
|
+
pending = undefined;
|
|
46
|
+
client = undefined;
|
|
47
|
+
await loading;
|
|
48
|
+
await previous?.destroy();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/runtime/controller.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,gBAAgB,CAC9B,MAAqB,EACrB,IAA+B,EAC/B,OAAiC;IAEjC,IAAI,MAA2B,CAAC;IAChC,IAAI,OAAiD,CAAC;IACtD,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,OAAO;QACL,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,KAAK;YACH,IAAI,CAAC,MAAM,CAAC,GAAG;gBAAE,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACnD,IAAI,MAAM;gBAAE,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC3C,IAAI,OAAO;gBAAE,OAAO,OAAO,CAAC;YAC5B,MAAM,OAAO,GAAG,UAAU,CAAC;YAC3B,MAAM,SAAS,GAAG,IAAI,EAAE;iBACrB,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;gBACnB,IAAI,OAAO,KAAK,UAAU;oBAAE,OAAO,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;YACtF,CAAC,CAAC;iBACD,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;gBACtB,IAAI,CAAC,OAAO;oBAAE,OAAO;gBACrB,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;oBAC3B,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;oBACxB,OAAO;gBACT,CAAC;gBACD,MAAM,GAAG,OAAO,CAAC;gBACjB,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBACxB,OAAO,CAAC,KAAK,CAAC,CAAC;gBACf,OAAO,SAAS,CAAC;YACnB,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE;gBACZ,IAAI,OAAO,KAAK,SAAS;oBAAE,OAAO,GAAG,SAAS,CAAC;YACjD,CAAC,CAAC,CAAC;YACL,OAAO,GAAG,SAAS,CAAC;YACpB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,KAAK,CAAC,IAAI;YACR,UAAU,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,OAAO,CAAC;YACxB,MAAM,QAAQ,GAAG,MAAM,CAAC;YACxB,OAAO,GAAG,SAAS,CAAC;YACpB,MAAM,GAAG,SAAS,CAAC;YACnB,MAAM,OAAO,CAAC;YACd,MAAM,QAAQ,EAAE,OAAO,EAAE,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/runtime/plugin.ts"],"names":[],"mappings":";;;;;AAIA,wBAkBG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineNuxtPlugin, onNuxtReady, useRuntimeConfig } from '#app';
|
|
2
|
+
import { createController } from './controller.js';
|
|
3
|
+
export default defineNuxtPlugin({
|
|
4
|
+
name: 'minihog',
|
|
5
|
+
setup() {
|
|
6
|
+
const config = useRuntimeConfig().public.minihog;
|
|
7
|
+
const controller = createController(typeof window === 'undefined' ? { ...config, key: '' } : config, () => import('#minihog-init').then(({ initialize }) => initialize), (error) => console.warn('[minihog] Analytics could not start.', error));
|
|
8
|
+
if (typeof window !== 'undefined' && config.start !== 'manual') {
|
|
9
|
+
onNuxtReady(() => {
|
|
10
|
+
if (config.start === 'idle' && 'requestIdleCallback' in window) {
|
|
11
|
+
window.requestIdleCallback(() => void controller.start(), { timeout: 2000 });
|
|
12
|
+
}
|
|
13
|
+
else
|
|
14
|
+
void controller.start();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return { provide: { minihog: controller } };
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/runtime/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,eAAe,gBAAgB,CAAC;IAC9B,IAAI,EAAE,SAAS;IACf,KAAK;QACH,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC,MAAM,CAAC,OAAwB,CAAC;QAClE,MAAM,UAAU,GAAG,gBAAgB,CACjC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAC/D,GAAG,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAClE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,KAAK,CAAC,CACvE,CAAC;QACF,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC/D,WAAW,CAAC,GAAG,EAAE;gBACf,IAAI,MAAM,CAAC,KAAK,KAAK,MAAM,IAAI,qBAAqB,IAAI,MAAM,EAAE,CAAC;oBAC/D,MAAM,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC,KAAK,UAAU,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/E,CAAC;;oBAAM,KAAK,UAAU,CAAC,KAAK,EAAE,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC;IAC9C,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../../src/runtime/server/body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,mFAAmF;AACnF,wBAAsB,WAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBlF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Limit body memory without destroying the socket before Nitro can return 413. */
|
|
2
|
+
export async function limitedBody(stream, limit) {
|
|
3
|
+
const reader = stream.iterator({ destroyOnReturn: false });
|
|
4
|
+
const decoder = new TextDecoder();
|
|
5
|
+
let size = 0;
|
|
6
|
+
let body = '';
|
|
7
|
+
try {
|
|
8
|
+
while (true) {
|
|
9
|
+
const chunk = await reader.next();
|
|
10
|
+
if (chunk.done)
|
|
11
|
+
break;
|
|
12
|
+
size += chunk.value.byteLength;
|
|
13
|
+
if (size > limit) {
|
|
14
|
+
throw new RangeError('Analytics payload too large');
|
|
15
|
+
}
|
|
16
|
+
body += decoder.decode(chunk.value, { stream: true });
|
|
17
|
+
}
|
|
18
|
+
return body + decoder.decode();
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
await reader.return?.();
|
|
22
|
+
// Drain unread bytes without retaining them. H3 1.x's Web Stream adapter does
|
|
23
|
+
// not detach its end handler on cancellation and otherwise throws on close.
|
|
24
|
+
if (!stream.readableEnded)
|
|
25
|
+
stream.resume();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../../src/runtime/server/body.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAgB,EAAE,KAAa;IAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,CAAC;QACH,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAClC,IAAI,KAAK,CAAC,IAAI;gBAAE,MAAM;YACtB,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC;YAC/B,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC;gBACjB,MAAM,IAAI,UAAU,CAAC,6BAA6B,CAAC,CAAC;YACtD,CAAC;YACD,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACjC,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QACxB,8EAA8E;QAC9E,4EAA4E;QAC5E,IAAI,CAAC,MAAM,CAAC,aAAa;YAAE,MAAM,CAAC,MAAM,EAAE,CAAC;IAC7C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/runtime/server/proxy.ts"],"names":[],"mappings":";AAaA,wBAiDG"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createError, defineEventHandler, getHeader, getRequestHeaders, getRequestURL, setHeader, setResponseStatus } from 'h3';
|
|
2
|
+
import { useRuntimeConfig } from '#imports';
|
|
3
|
+
import { proxyTarget } from './routing.js';
|
|
4
|
+
import { limitedBody } from './body.js';
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
const config = useRuntimeConfig(event).minihog;
|
|
7
|
+
const target = proxyTarget(getRequestURL(event), event.method, config);
|
|
8
|
+
if (!target)
|
|
9
|
+
throw createError({ statusCode: 404, statusMessage: 'Analytics endpoint not found' });
|
|
10
|
+
const length = Number(getHeader(event, 'content-length') ?? 0);
|
|
11
|
+
const limit = 2 * 1024 * 1024;
|
|
12
|
+
if (length > limit)
|
|
13
|
+
throw createError({ statusCode: 413, statusMessage: 'Analytics payload too large' });
|
|
14
|
+
let body;
|
|
15
|
+
try {
|
|
16
|
+
if (event.method === 'POST')
|
|
17
|
+
body = await limitedBody(event.node.req, limit);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof RangeError)
|
|
21
|
+
throw createError({ statusCode: 413, statusMessage: 'Analytics payload too large' });
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
const incoming = getRequestHeaders(event);
|
|
25
|
+
const headers = {};
|
|
26
|
+
// Forward browser context for flag runtime detection and GeoIP, never site credentials.
|
|
27
|
+
for (const name of [
|
|
28
|
+
'content-type',
|
|
29
|
+
'user-agent',
|
|
30
|
+
'origin',
|
|
31
|
+
'referer',
|
|
32
|
+
'sec-fetch-site',
|
|
33
|
+
'sec-fetch-mode',
|
|
34
|
+
'x-forwarded-for'
|
|
35
|
+
]) {
|
|
36
|
+
const value = incoming[name];
|
|
37
|
+
if (typeof value === 'string')
|
|
38
|
+
headers[name] = value;
|
|
39
|
+
}
|
|
40
|
+
let response;
|
|
41
|
+
try {
|
|
42
|
+
response = await fetch(target, {
|
|
43
|
+
method: event.method,
|
|
44
|
+
headers,
|
|
45
|
+
body,
|
|
46
|
+
redirect: 'error',
|
|
47
|
+
signal: AbortSignal.timeout(10000)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw createError({ statusCode: 502, statusMessage: 'Analytics upstream unavailable' });
|
|
52
|
+
}
|
|
53
|
+
setResponseStatus(event, response.status);
|
|
54
|
+
for (const name of ['content-type', 'retry-after']) {
|
|
55
|
+
const value = response.headers.get(name);
|
|
56
|
+
if (value)
|
|
57
|
+
setHeader(event, name, value);
|
|
58
|
+
}
|
|
59
|
+
setHeader(event, 'cache-control', 'no-store');
|
|
60
|
+
return response.body;
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/runtime/server/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,iBAAiB,EAClB,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,eAAe,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;IAChD,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;IAC/C,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CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACvD,CAAC;IACD,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;YAC7B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,OAAO;YACP,IAAI;YACJ,QAAQ,EAAE,OAAO;YACjB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;SACnC,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,WAAW,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,gCAAgC,EAAE,CAAC,CAAC;IAC1F,CAAC;IACD,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,EAAE,CAAC;QACnD,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,KAAK;YAAE,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,SAAS,CAAC,KAAK,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC;IAC9C,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProxyOptions } from '../../types.js';
|
|
2
|
+
/** An endpoint allowlist prevents proxying arbitrary URLs, scripts, or management APIs. */
|
|
3
|
+
export declare function proxyTarget(url: URL, method: string, options: ProxyOptions): string | undefined;
|
|
4
|
+
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../../src/runtime/server/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAW/F"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** An endpoint allowlist prevents proxying arbitrary URLs, scripts, or management APIs. */
|
|
2
|
+
export function proxyTarget(url, method, options) {
|
|
3
|
+
if (!url.pathname.startsWith(`${options.path}/`))
|
|
4
|
+
return;
|
|
5
|
+
const path = url.pathname.slice(options.path.length);
|
|
6
|
+
const ingestion = /^\/(batch|s)\/$/.test(path) || path === '/i/v0/e/';
|
|
7
|
+
const flags = /^\/flags\/?$/.test(path);
|
|
8
|
+
const config = /^\/array\/[a-zA-Z0-9_-]+\/config$/.test(path);
|
|
9
|
+
const surveys = path === '/api/surveys/';
|
|
10
|
+
if ((ingestion || flags) && method !== 'POST')
|
|
11
|
+
return;
|
|
12
|
+
if ((config || surveys) && method !== 'GET')
|
|
13
|
+
return;
|
|
14
|
+
if (!ingestion && !flags && !config && !surveys)
|
|
15
|
+
return;
|
|
16
|
+
return `${config ? options.assetsHost : options.host}${path}${url.search}`;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../../src/runtime/server/routing.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,MAAM,UAAU,WAAW,CAAC,GAAQ,EAAE,MAAc,EAAE,OAAqB;IACzE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC;QAAE,OAAO;IACzD,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,iBAAiB,CAAC,IAAI,CAA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