@storewatch/nextjs 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +17 -2
- package/dist/config.d.ts +35 -0
- package/dist/config.js +17 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +11 -0
- package/package.json +46 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Edin Skeja
|
|
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,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @storewatch/nextjs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Storewatch for Next.js (15.3+): start tracking before hydration and send
|
|
4
|
+
events through your own domain, so ad blockers and CORS don't get in the way.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
// next.config.ts
|
|
8
|
+
import { withStorewatch } from "@storewatch/nextjs/config";
|
|
9
|
+
export default withStorewatch(nextConfig, { ingestUrl: "https://ingest.example.com" });
|
|
10
|
+
|
|
11
|
+
// instrumentation-client.ts
|
|
12
|
+
import { init } from "@storewatch/nextjs";
|
|
13
|
+
init({ publicKey: process.env.NEXT_PUBLIC_STOREWATCH_KEY! });
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Events go to `/_sw/v1/batch` on your domain. If your proxy or middleware
|
|
17
|
+
matcher covers every path, exclude `/_sw`. Track commerce events with
|
|
18
|
+
`getStorewatch().track(…)` or `useStorewatch()`.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds a first-party proxy route to a Next.js config: the SDK posts to
|
|
3
|
+
* `/_sw/v1/batch` on the store's own domain and Next forwards it to ingest.
|
|
4
|
+
* Same-origin requests survive ad blockers and need no CORS.
|
|
5
|
+
*
|
|
6
|
+
* // next.config.ts
|
|
7
|
+
* import { withStorewatch } from "@storewatch/nextjs/config";
|
|
8
|
+
* export default withStorewatch(nextConfig, { ingestUrl: "https://in.storewatch.example" });
|
|
9
|
+
*
|
|
10
|
+
* If your proxy/middleware matcher covers every path, exclude `/_sw`.
|
|
11
|
+
*/
|
|
12
|
+
type Rewrite = {
|
|
13
|
+
source: string;
|
|
14
|
+
destination: string;
|
|
15
|
+
};
|
|
16
|
+
type RewriteSet = {
|
|
17
|
+
beforeFiles?: Rewrite[];
|
|
18
|
+
afterFiles?: Rewrite[];
|
|
19
|
+
fallback?: Rewrite[];
|
|
20
|
+
};
|
|
21
|
+
export type WithStorewatchOptions = {
|
|
22
|
+
/** Base URL of the ingest service, without a trailing slash. */
|
|
23
|
+
ingestUrl: string;
|
|
24
|
+
/** Path prefix on the store's domain. Default "/_sw". */
|
|
25
|
+
path?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* `T extends object` rather than `ConfigWithRewrites`: a type whose properties
|
|
29
|
+
* are all optional is a "weak type", and TypeScript would reject any config
|
|
30
|
+
* that shares none of them, i.e. most Next configs.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withStorewatch<T extends object>(config: T, options: WithStorewatchOptions): T & {
|
|
33
|
+
rewrites: () => Promise<RewriteSet>;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
function withStorewatch(config, options) {
|
|
3
|
+
const existingRewrites = config.rewrites;
|
|
4
|
+
const prefix = options.path ?? "/_sw";
|
|
5
|
+
const ours = { source: `${prefix}/:path*`, destination: `${options.ingestUrl.replace(/\/$/, "")}/:path*` };
|
|
6
|
+
return {
|
|
7
|
+
...config,
|
|
8
|
+
async rewrites() {
|
|
9
|
+
const existing = await existingRewrites?.() ?? [];
|
|
10
|
+
if (Array.isArray(existing)) return { beforeFiles: [ours], afterFiles: existing, fallback: [] };
|
|
11
|
+
return { ...existing, beforeFiles: [ours, ...existing.beforeFiles ?? []] };
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
withStorewatch
|
|
17
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recommended: initialise in `instrumentation-client.ts`, which Next runs once
|
|
3
|
+
* before hydration, so no event can be tracked before init and no provider is
|
|
4
|
+
* needed. `useStorewatch()` works anywhere; the provider is optional.
|
|
5
|
+
*/
|
|
6
|
+
export { StorewatchProvider, getStorewatch, init, useStorewatch, money, type StorewatchProviderProps } from "@storewatch/react";
|
|
7
|
+
export type { Consent, Storewatch, StorewatchOptions } from "@storewatch/react";
|
package/dist/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storewatch/nextjs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Storewatch for Next.js: provider plus a first-party ingest proxy.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./config": {
|
|
15
|
+
"types": "./dist/config.d.ts",
|
|
16
|
+
"import": "./dist/config.js",
|
|
17
|
+
"default": "./dist/config.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@storewatch/react": "0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"next": ">=15.3",
|
|
31
|
+
"react": ">=18"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/react": "^19.3.0",
|
|
35
|
+
"react": "^19.3.1",
|
|
36
|
+
"tsup": "^9.0.0",
|
|
37
|
+
"@storewatch/config": "0.0.0"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"storewatch",
|
|
41
|
+
"analytics",
|
|
42
|
+
"ecommerce"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "rm -rf dist && tsup && tsc -p tsconfig.build.json",
|
|
46
|
+
"typecheck": "tsc -p .",
|
|
47
|
+
"test": "vitest run"
|
|
48
|
+
}
|
|
6
49
|
}
|