@zachariaz/strapi-plugin-experience-context 0.0.0-stage → 0.1.0-dev.2

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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -2
  3. package/dist/_chunks/en-8ms9Hfxr.mjs +27 -0
  4. package/dist/_chunks/en-yERKDiB0.js +27 -0
  5. package/dist/admin/index.js +464 -0
  6. package/dist/admin/index.mjs +448 -0
  7. package/dist/admin/src/api/client.d.ts +13 -0
  8. package/dist/admin/src/api/types.d.ts +93 -0
  9. package/dist/admin/src/api/useInspect.d.ts +3 -0
  10. package/dist/admin/src/components/BlockMarkers.d.ts +12 -0
  11. package/dist/admin/src/components/ExperienceModal.d.ts +28 -0
  12. package/dist/admin/src/components/HeaderBadge.d.ts +19 -0
  13. package/dist/admin/src/components/Initializer.d.ts +5 -0
  14. package/dist/admin/src/components/ModalTrigger.d.ts +10 -0
  15. package/dist/admin/src/contentManagerHooks/editView.d.ts +7 -0
  16. package/dist/admin/src/index.d.ts +17 -0
  17. package/dist/admin/src/pluginId.d.ts +2 -0
  18. package/dist/admin/src/utils/dzSlots.d.ts +16 -0
  19. package/dist/admin/src/utils/labels.d.ts +30 -0
  20. package/dist/admin/src/utils/markers.d.ts +12 -0
  21. package/dist/admin/src/utils/modal.d.ts +10 -0
  22. package/dist/admin/src/utils/targets.d.ts +12 -0
  23. package/dist/server/index.js +3780 -0
  24. package/dist/server/index.mjs +3781 -0
  25. package/dist/server/src/admin-api/access.d.ts +40 -0
  26. package/dist/server/src/admin-api/inspect.d.ts +132 -0
  27. package/dist/server/src/admin-api/mark.d.ts +9 -0
  28. package/dist/server/src/block-keys/index.d.ts +16 -0
  29. package/dist/server/src/block-keys/middleware.d.ts +17 -0
  30. package/dist/server/src/block-keys/stamp.d.ts +55 -0
  31. package/dist/server/src/block-keys/store.d.ts +33 -0
  32. package/dist/server/src/block-keys/targets.d.ts +43 -0
  33. package/dist/server/src/bootstrap.d.ts +16 -0
  34. package/dist/server/src/changes.d.ts +80 -0
  35. package/dist/server/src/config/index.d.ts +67 -0
  36. package/dist/server/src/constants.d.ts +18 -0
  37. package/dist/server/src/content-types/index.d.ts +309 -0
  38. package/dist/server/src/controllers/admin.d.ts +10 -0
  39. package/dist/server/src/controllers/experience.d.ts +15 -0
  40. package/dist/server/src/controllers/index.d.ts +16 -0
  41. package/dist/server/src/destroy.d.ts +5 -0
  42. package/dist/server/src/index.d.ts +441 -0
  43. package/dist/server/src/integrity/index.d.ts +34 -0
  44. package/dist/server/src/integrity/orphans.d.ts +40 -0
  45. package/dist/server/src/mcp/index.d.ts +2 -0
  46. package/dist/server/src/mcp/operations.d.ts +815 -0
  47. package/dist/server/src/mcp/permissions.d.ts +56 -0
  48. package/dist/server/src/mcp/tools.d.ts +59 -0
  49. package/dist/server/src/model/content.d.ts +32 -0
  50. package/dist/server/src/model/mapping.d.ts +90 -0
  51. package/dist/server/src/model/records.d.ts +132 -0
  52. package/dist/server/src/model/store.d.ts +44 -0
  53. package/dist/server/src/model/target.d.ts +40 -0
  54. package/dist/server/src/policies/index.d.ts +4 -0
  55. package/dist/server/src/rbac/index.d.ts +24 -0
  56. package/dist/server/src/read-path/editor.d.ts +28 -0
  57. package/dist/server/src/read-path/gate.d.ts +26 -0
  58. package/dist/server/src/read-path/index.d.ts +12 -0
  59. package/dist/server/src/read-path/loader.d.ts +31 -0
  60. package/dist/server/src/read-path/middleware.d.ts +32 -0
  61. package/dist/server/src/read-path/payload.d.ts +34 -0
  62. package/dist/server/src/read-path/populate.d.ts +6 -0
  63. package/dist/server/src/register.d.ts +14 -0
  64. package/dist/server/src/registry/index.d.ts +29 -0
  65. package/dist/server/src/registry/unomi.d.ts +53 -0
  66. package/dist/server/src/routes/index.d.ts +25 -0
  67. package/dist/server/src/services/index.d.ts +79 -0
  68. package/package.json +140 -4
  69. package/scripts/experience-smoke.mjs +430 -0
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Adds `blockKey` to `fields` in `populate[zone].on[component]` for every
3
+ * targeted zone and keyed component. String, array and `'*'` populates
4
+ * select every column already and are returned unchanged.
5
+ */
6
+ export declare function ensureBlockKeyFields(populate: unknown, zones: readonly string[], keyedComponents: ReadonlySet<string>): unknown;
@@ -0,0 +1,14 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ /**
3
+ * Register phase:
4
+ * - adds the hidden `blockKey` attribute to every targeted `zone.*`
5
+ * component, before Strapi syncs the database schema;
6
+ * - registers the MCP tools (Strapi's MCP server starts in bootstrap and
7
+ * refuses registrations after that);
8
+ * - declares `?withExperience` via `contentAPI.addQueryParams`;
9
+ * - marks the target content types in `pluginOptions` for the admin.
10
+ */
11
+ declare const register: ({ strapi }: {
12
+ strapi: Core.Strapi;
13
+ }) => void;
14
+ export default register;
@@ -0,0 +1,29 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import { type Registry, type RegistryEntry } from '@zachariaz/experience-context-core';
3
+ import { type UnomiDefinitions } from './unomi';
4
+ /**
5
+ * Registry provider (plan §5.3, S7.2): the app's static registry
6
+ * (`config/experience-registry.ts`), plus content-variants segments that
7
+ * have an `externalId` (as `audience/<slug>`), plus, with the `unomi`
8
+ * option, the live Unomi segment definitions (./unomi), plus the plugin's
9
+ * own experiments. The static registry wins on labels: an id is kept from
10
+ * the first source that names it. It answers "which ids exist and what are they called" and
11
+ * nothing else: ids, labels and descriptions only, never profile ids,
12
+ * names, emails, events or scores. An id missing here is a validation
13
+ * warning, never an error.
14
+ */
15
+ export declare const SEGMENT_UID = "plugin::content-variants.segment";
16
+ export declare const REGISTRY_KINDS: readonly ["audiences", "traits", "affinities", "concepts", "experiments"];
17
+ export type RegistryKind = (typeof REGISTRY_KINDS)[number];
18
+ /** Keeps exactly `id`, `label` and `description` (strings). */
19
+ export declare function sanitizeEntry(e: unknown): RegistryEntry | null;
20
+ /** content-variants segments with an `externalId` → `audience/<slug>` (pure). */
21
+ export declare function segmentAudiences(segments: unknown[]): RegistryEntry[];
22
+ /** Builds the registry from its sources (pure). */
23
+ export declare function buildRegistry(config: Partial<Record<RegistryKind, unknown[]>>, segments: unknown[], experiments: Array<{
24
+ key?: unknown;
25
+ name?: unknown;
26
+ description?: unknown;
27
+ }>, unomi?: UnomiDefinitions): Required<Registry>;
28
+ /** The live registry of a running app. */
29
+ export declare function loadRegistry(strapi: Core.Strapi): Promise<Required<Registry>>;
@@ -0,0 +1,53 @@
1
+ /// <reference types="node" />
2
+ import { type RegistryEntry } from '@zachariaz/experience-context-core';
3
+ /**
4
+ * Registry source: the segment definitions of a live Unomi (plan S7.2).
5
+ *
6
+ * Reads `GET <url>/segments` (definitions only: id, name, description,
7
+ * scope; never profiles) and turns them into registry entries:
8
+ *
9
+ * audience.<slug> → audiences `audience/<slug>`
10
+ * affinity.<vocabulary>.<slug>.<band> → affinities `<vocabulary>/<slug>` (one per concept)
11
+ *
12
+ * Any other segment (no `audience.` prefix, `exp.`, `sys.`, ...) is not
13
+ * ours and is skipped. Traits are profile properties, not segments, so
14
+ * they stay in the static registry.
15
+ *
16
+ * Cached for `ttlSeconds` per url and scope. Fail-soft: an unreachable or
17
+ * failing Unomi logs one warning and keeps the last good definitions (or
18
+ * none), so the static registry still answers.
19
+ */
20
+ export interface UnomiSourceConfig {
21
+ /** Unomi REST base including `/cxs`, e.g. `http://localhost:8181/cxs`. Empty = off. */
22
+ url?: string;
23
+ /** Basic credentials: on Unomi 3 an admin login, on Unomi 4 the tenant id and a tenant key. */
24
+ username?: string;
25
+ password?: string;
26
+ /** Only segments of this Unomi scope (e.g. `reactionary-storefront`). Unset = every scope. */
27
+ scope?: string;
28
+ /** Cache lifetime, default 300. */
29
+ ttlSeconds?: number;
30
+ /** Request timeout, default 3000. */
31
+ timeoutMs?: number;
32
+ }
33
+ export interface UnomiDefinitions {
34
+ audiences: RegistryEntry[];
35
+ affinities: RegistryEntry[];
36
+ }
37
+ type Logger = {
38
+ warn: (msg: string) => void;
39
+ info: (msg: string) => void;
40
+ };
41
+ type Fetch = typeof fetch;
42
+ /** Segment metadata list → registry entries (pure). */
43
+ export declare function definitionsFromSegments(segments: unknown[], scope?: string): UnomiDefinitions;
44
+ /** Every segment's metadata, page by page. */
45
+ export declare function fetchSegments(config: UnomiSourceConfig, fetchImpl?: Fetch): Promise<unknown[]>;
46
+ /** Test hook: forget every cached answer. */
47
+ export declare const resetUnomiCache: () => void;
48
+ export declare const unomiEnabled: (config: UnomiSourceConfig | undefined) => config is UnomiSourceConfig & {
49
+ url: string;
50
+ };
51
+ /** The cached definitions; refreshed after the TTL; never throws. */
52
+ export declare function loadUnomiDefinitions(config: UnomiSourceConfig | undefined, log: Logger, fetchImpl?: Fetch, now?: () => number): Promise<UnomiDefinitions>;
53
+ export {};
@@ -0,0 +1,25 @@
1
+ declare const _default: {
2
+ 'content-api': {
3
+ type: "content-api";
4
+ routes: {
5
+ method: string;
6
+ path: string;
7
+ handler: string;
8
+ config: {
9
+ policies: never[];
10
+ };
11
+ }[];
12
+ };
13
+ admin: {
14
+ type: "admin";
15
+ routes: {
16
+ method: string;
17
+ path: string;
18
+ handler: string;
19
+ config: {
20
+ policies: string[];
21
+ };
22
+ }[];
23
+ };
24
+ };
25
+ export default _default;
@@ -0,0 +1,79 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import { type BackfillOptions } from '../block-keys/store';
3
+ import { type EditorAttachOptions } from '../read-path/editor';
4
+ declare const _default: {
5
+ blockKeys: ({ strapi }: {
6
+ strapi: Core.Strapi;
7
+ }) => {
8
+ targets(): {
9
+ contentTypes: {
10
+ [k: string]: string[];
11
+ };
12
+ components: string[];
13
+ };
14
+ backfill(options?: BackfillOptions): Promise<import("../block-keys").BackfillReport>;
15
+ stamp(uid: string, data: unknown): Promise<import("../block-keys/stamp").StampEvent[]>;
16
+ };
17
+ editor: ({ strapi }: {
18
+ strapi: Core.Strapi;
19
+ }) => {
20
+ attach(options: EditorAttachOptions): Promise<import("../read-path/editor").EditorAttachResult>;
21
+ };
22
+ integrity: ({ strapi }: {
23
+ strapi: Core.Strapi;
24
+ }) => {
25
+ recompute: (uid: string, documentId: string, reason?: string) => Promise<{
26
+ entity: string;
27
+ documentId: string | null;
28
+ blockKey: string | null;
29
+ locale: string | null;
30
+ orphaned: boolean;
31
+ }[]>;
32
+ cascadeDelete: (uid: string, documentId: string) => Promise<{
33
+ variations: (string | null)[];
34
+ annotations: (string | null)[];
35
+ }>;
36
+ currentKeys: (uid: string, documentId: string) => Promise<import("../integrity/orphans").PresentKeys | null>;
37
+ orphanedNow: (uid: string, documentId: string, target: {
38
+ locale?: string | null | undefined;
39
+ blockKey?: string | null | undefined;
40
+ }) => Promise<boolean>;
41
+ };
42
+ registry: ({ strapi }: {
43
+ strapi: Core.Strapi;
44
+ }) => {
45
+ get: () => Promise<Required<import("@zachariaz/experience-context-core").Registry>>;
46
+ presets: () => import("@zachariaz/experience-context-core").Preset[];
47
+ };
48
+ store: ({ strapi }: {
49
+ strapi: Core.Strapi;
50
+ }) => {
51
+ listVariations: (filters?: {
52
+ targetUid?: string | undefined;
53
+ targetDocumentId?: string | string[] | undefined;
54
+ locale?: string | null | undefined;
55
+ sectionKey?: string | undefined;
56
+ blockKey?: string | undefined;
57
+ }) => Promise<import("../model/records").VariationRecord[]>;
58
+ createVariation: (record: Omit<import("../model/records").VariationRecord, "documentId">, ctx: import("../model/store").WriteContext) => Promise<import("../model/records").VariationRecord>;
59
+ updateVariation: (before: import("../model/records").VariationRecord, patch: Partial<import("../model/records").VariationRecord>, ctx: import("../model/store").WriteContext) => Promise<import("../model/records").VariationRecord>;
60
+ deleteVariation: (before: import("../model/records").VariationRecord, ctx: import("../model/store").WriteContext) => Promise<void>;
61
+ listAnnotations: (filters?: {
62
+ targetUid?: string | undefined;
63
+ targetDocumentId?: string | string[] | undefined;
64
+ locale?: string | null | undefined;
65
+ blockKey?: string | null | undefined;
66
+ }) => Promise<import("../model/records").AnnotationRecord[]>;
67
+ setAnnotation: (existing: import("../model/records").AnnotationRecord | undefined, record: Omit<import("../model/records").AnnotationRecord, "documentId" | "orphaned" | "source" | "createdBy" | "correlationId"> & {
68
+ orphaned?: boolean | undefined;
69
+ }, ctx: import("../model/store").WriteContext) => Promise<import("../model/records").AnnotationRecord | null>;
70
+ deleteAnnotation: (before: import("../model/records").AnnotationRecord, ctx: import("../model/store").WriteContext) => Promise<void>;
71
+ listExperiments: (keys?: string[] | undefined) => Promise<import("../model/records").ExperimentRecord[]>;
72
+ getExperiment: (key: string) => Promise<import("../model/records").ExperimentRecord | undefined>;
73
+ saveExperiment: (existing: import("../model/records").ExperimentRecord | undefined, record: Omit<import("../model/records").ExperimentRecord, "documentId" | "source" | "createdBy" | "correlationId">, ctx: import("../model/store").WriteContext) => Promise<import("../model/records").ExperimentRecord>;
74
+ deleteExperiment: (before: import("../model/records").ExperimentRecord, ctx: import("../model/store").WriteContext) => Promise<void>;
75
+ variationsOfExperiment: (key: string) => Promise<import("../model/records").VariationRecord[]>;
76
+ logBlock: (action: "create" | "delete", block: Record<string, unknown>, ctx: import("../model/store").WriteContext) => Promise<void>;
77
+ };
78
+ };
79
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,142 @@
1
1
  {
2
2
  "name": "@zachariaz/strapi-plugin-experience-context",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-dev.2",
4
+ "description": "Strapi v5 plugin: read-only Experience Manager extension for inspecting and simulating context-aware content (concepts, audience variations, experiment outcomes) authored through MCP",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/SolteqExperienceCommerce/strapi-plugin-experience-context.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/SolteqExperienceCommerce/strapi-plugin-experience-context/issues"
12
+ },
13
+ "homepage": "https://github.com/SolteqExperienceCommerce/strapi-plugin-experience-context#readme",
14
+ "keywords": [
15
+ "strapi",
16
+ "strapi-plugin",
17
+ "strapi-v5",
18
+ "experience",
19
+ "experiments",
20
+ "mcp"
21
+ ],
22
+ "engines": {
23
+ "node": ">=22.0.0 <=24.x.x"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "strapi": {
29
+ "kind": "plugin",
30
+ "name": "experience-context",
31
+ "displayName": "Experience Context",
32
+ "description": "Concepts, audience variations and experiment outcomes on pages and blocks; read-only inspection, writes through MCP"
33
+ },
34
+ "type": "commonjs",
35
+ "exports": {
36
+ "./package.json": "./package.json",
37
+ "./strapi-admin": {
38
+ "types": "./dist/admin/src/index.d.ts",
39
+ "source": "./admin/src/index.tsx",
40
+ "import": "./dist/admin/index.mjs",
41
+ "require": "./dist/admin/index.js",
42
+ "default": "./dist/admin/index.js"
43
+ },
44
+ "./strapi-server": {
45
+ "types": "./dist/server/src/index.d.ts",
46
+ "source": "./server/src/index.ts",
47
+ "import": "./dist/server/index.mjs",
48
+ "require": "./dist/server/index.js",
49
+ "default": "./dist/server/index.js"
50
+ }
51
+ },
52
+ "bin": {
53
+ "experience-smoke": "scripts/experience-smoke.mjs"
54
+ },
55
+ "files": [
56
+ "dist",
57
+ "scripts/experience-smoke.mjs"
58
+ ],
59
+ "scripts": {
60
+ "build": "strapi-plugin build",
61
+ "watch": "strapi-plugin watch",
62
+ "watch:link": "strapi-plugin watch:link",
63
+ "verify": "strapi-plugin verify && node scripts/check-exports.cjs",
64
+ "lint": "eslint .",
65
+ "test": "vitest run",
66
+ "typecheck": "tsc -p server/tsconfig.json --noEmit && tsc -p admin/tsconfig.json --noEmit",
67
+ "local:publish": "bash scripts/local-dev.sh",
68
+ "smoke": "node scripts/experience-smoke.mjs"
69
+ },
70
+ "dependencies": {
71
+ "@zachariaz/experience-context-core": "^0.1.0-dev.0"
72
+ },
73
+ "devDependencies": {
74
+ "@edge-runtime/vm": "^5.0.0",
75
+ "@eslint/js": "^9.39.0",
76
+ "@strapi/admin": "5.59.0",
77
+ "@strapi/content-manager": "5.59.0",
78
+ "@strapi/design-system": "^2.0.0",
79
+ "@strapi/icons": "^2.0.0",
80
+ "@strapi/sdk-plugin": "^5.4.0",
81
+ "@strapi/strapi": "5.59.0",
82
+ "@strapi/utils": "5.59.0",
83
+ "@types/react": "^18.3.31",
84
+ "@types/react-dom": "^18.3.7",
85
+ "esbuild": "^0.25.0",
86
+ "eslint": "^9.39.0",
87
+ "globals": "^16.0.0",
88
+ "react": "^18.0.0",
89
+ "react-dom": "^18.0.0",
90
+ "react-intl": "^6.0.0",
91
+ "react-router-dom": "^6.0.0",
92
+ "styled-components": "^6.0.0",
93
+ "typescript": "^5.0.0",
94
+ "typescript-eslint": "^8.0.0",
95
+ "vitest": "^4.1.2"
96
+ },
97
+ "peerDependencies": {
98
+ "@strapi/admin": "^5.0.0",
99
+ "@strapi/content-manager": "^5.39.0",
100
+ "@strapi/design-system": "^2.0.0",
101
+ "@strapi/icons": "^2.0.0",
102
+ "@strapi/strapi": "^5.0.0",
103
+ "@strapi/utils": "^5.0.0",
104
+ "react": "^18.0.0",
105
+ "react-dom": "^18.0.0",
106
+ "react-intl": "^6.0.0",
107
+ "react-router-dom": "^6.0.0",
108
+ "styled-components": "^6.0.0"
109
+ },
110
+ "peerDependenciesMeta": {
111
+ "@strapi/admin": {
112
+ "optional": true
113
+ },
114
+ "@strapi/content-manager": {
115
+ "optional": true
116
+ },
117
+ "@strapi/design-system": {
118
+ "optional": true
119
+ },
120
+ "@strapi/icons": {
121
+ "optional": true
122
+ },
123
+ "@strapi/strapi": {
124
+ "optional": true
125
+ },
126
+ "react": {
127
+ "optional": true
128
+ },
129
+ "react-dom": {
130
+ "optional": true
131
+ },
132
+ "react-router-dom": {
133
+ "optional": true
134
+ },
135
+ "styled-components": {
136
+ "optional": true
137
+ },
138
+ "react-intl": {
139
+ "optional": true
140
+ }
141
+ }
142
+ }