@sparkletree/core 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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +105 -0
  3. package/dist/analytics.d.ts +75 -0
  4. package/dist/analytics.d.ts.map +1 -0
  5. package/dist/analytics.js +170 -0
  6. package/dist/analytics.js.map +1 -0
  7. package/dist/audio.d.ts +85 -0
  8. package/dist/audio.d.ts.map +1 -0
  9. package/dist/audio.js +465 -0
  10. package/dist/audio.js.map +1 -0
  11. package/dist/client.d.ts +79 -0
  12. package/dist/client.d.ts.map +1 -0
  13. package/dist/client.js +251 -0
  14. package/dist/client.js.map +1 -0
  15. package/dist/context.d.ts +104 -0
  16. package/dist/context.d.ts.map +1 -0
  17. package/dist/context.js +277 -0
  18. package/dist/context.js.map +1 -0
  19. package/dist/fragments.d.ts +108 -0
  20. package/dist/fragments.d.ts.map +1 -0
  21. package/dist/fragments.js +223 -0
  22. package/dist/fragments.js.map +1 -0
  23. package/dist/index.d.ts +31 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +30 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/protocol.d.ts +70 -0
  28. package/dist/protocol.d.ts.map +1 -0
  29. package/dist/protocol.js +97 -0
  30. package/dist/protocol.js.map +1 -0
  31. package/dist/publishableKey.d.ts +38 -0
  32. package/dist/publishableKey.d.ts.map +1 -0
  33. package/dist/publishableKey.js +69 -0
  34. package/dist/publishableKey.js.map +1 -0
  35. package/dist/safeUrl.d.ts +56 -0
  36. package/dist/safeUrl.d.ts.map +1 -0
  37. package/dist/safeUrl.js +117 -0
  38. package/dist/safeUrl.js.map +1 -0
  39. package/dist/sse.d.ts +51 -0
  40. package/dist/sse.d.ts.map +1 -0
  41. package/dist/sse.js +137 -0
  42. package/dist/sse.js.map +1 -0
  43. package/dist/state.d.ts +321 -0
  44. package/dist/state.d.ts.map +1 -0
  45. package/dist/state.js +594 -0
  46. package/dist/state.js.map +1 -0
  47. package/dist/text.d.ts +10 -0
  48. package/dist/text.d.ts.map +1 -0
  49. package/dist/text.js +29 -0
  50. package/dist/text.js.map +1 -0
  51. package/dist/theme.d.ts +52 -0
  52. package/dist/theme.d.ts.map +1 -0
  53. package/dist/theme.js +88 -0
  54. package/dist/theme.js.map +1 -0
  55. package/dist/trust.d.ts +52 -0
  56. package/dist/trust.d.ts.map +1 -0
  57. package/dist/trust.js +95 -0
  58. package/dist/trust.js.map +1 -0
  59. package/dist/variant.d.ts +117 -0
  60. package/dist/variant.d.ts.map +1 -0
  61. package/dist/variant.js +167 -0
  62. package/dist/variant.js.map +1 -0
  63. package/dist/wire.d.ts +564 -0
  64. package/dist/wire.d.ts.map +1 -0
  65. package/dist/wire.js +133 -0
  66. package/dist/wire.js.map +1 -0
  67. package/package.json +55 -0
package/dist/wire.js ADDED
@@ -0,0 +1,133 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Code generated from shared/sparkletree/wire/contract.ts. DO NOT EDIT.
4
+ *
5
+ * Regenerate with `pnpm wire:generate` from the repo root.
6
+ * Editing this file by hand puts the Go edge and the Next twin back on
7
+ * separate contracts, which is the exact failure the SDK plan's decision (a)
8
+ * spends a workstream preventing.
9
+ */
10
+ // --- protocol ---------------------------------------------------------------
11
+ export const PROTOCOL_VERSIONS = [1, 2];
12
+ export const PROTOCOL_DEFAULT = 1;
13
+ export const PROTOCOL_CURRENT = 2;
14
+ export const PROTOCOL_PARAM = "st-protocol";
15
+ export const PROTOCOL_HEADER = "st-protocol";
16
+ export const PROTOCOL_RESPONSE_HEADER = "st-protocol";
17
+ /**
18
+ * Is this a version we implement? Absent/blank resolves to PROTOCOL_DEFAULT
19
+ * before it gets here.
20
+ */
21
+ export function isSupportedProtocol(version) {
22
+ return PROTOCOL_VERSIONS.includes(version);
23
+ }
24
+ /**
25
+ * Resolve the negotiated version from a header value and a query param.
26
+ * Header wins. Absent, blank, or unparseable resolves to PROTOCOL_DEFAULT —
27
+ * never an error, because every shell stamped into a customer page before
28
+ * negotiation existed sends nothing at all.
29
+ */
30
+ export function resolveProtocol(header, param) {
31
+ const raw = (header ?? param ?? '').trim();
32
+ if (!raw)
33
+ return PROTOCOL_DEFAULT;
34
+ const parsed = Number.parseInt(raw, 10);
35
+ if (!Number.isFinite(parsed) || parsed <= 0)
36
+ return PROTOCOL_DEFAULT;
37
+ return parsed;
38
+ }
39
+ // --- vocabularies -----------------------------------------------------------
40
+ export const COPY_MODES = ["generate", "replay"];
41
+ export const CONTENT_SOURCES = ["generated", "cached", "static"];
42
+ export const DEGRADE_REASONS = ["quota", "spend-cap", "upstream", "timeout"];
43
+ export const INTENTS = ["signup", "signin", "retain", "upsell", "reassure", "explain", "browse", "convert"];
44
+ export const FRAGMENT_KINDS = ["headline", "body", "cta", "label", "empty-state"];
45
+ export const FRAGMENT_WARMTHS = ["cold", "warming", "warm"];
46
+ export const SDK_PARAM = "sdk";
47
+ export const SDK_PARAM_VALUE = "1";
48
+ export const VARIANT_PARAM = "variant";
49
+ // --- catalog ----------------------------------------------------------------
50
+ export const EVENT_THEME_READY = "theme-ready";
51
+ export const EVENT_CTA_STYLE_READY = "cta-style-ready";
52
+ export const EVENT_EXPERIENCE_READY = "experience-ready";
53
+ export const EVENT_LAYOUT_READY = "layout-ready";
54
+ export const EVENT_BACKGROUND_READY = "background-ready";
55
+ export const EVENT_SEQUENCE_READY = "sequence-ready";
56
+ export const EVENT_VIDEO_READY = "video-ready";
57
+ export const EVENT_GREETING_START = "greeting-start";
58
+ export const EVENT_GREETING_CHUNK = "greeting-chunk";
59
+ export const EVENT_GREETING_DONE = "greeting-done";
60
+ export const EVENT_HEADLINE_START = "headline-start";
61
+ export const EVENT_HEADLINE_CHUNK = "headline-chunk";
62
+ export const EVENT_HEADLINE_DONE = "headline-done";
63
+ export const EVENT_BODY_START = "body-start";
64
+ export const EVENT_BODY_CHUNK = "body-chunk";
65
+ export const EVENT_BODY_DONE = "body-done";
66
+ export const EVENT_CTA_START = "cta-start";
67
+ export const EVENT_CTA_CHUNK = "cta-chunk";
68
+ export const EVENT_CTA_DONE = "cta-done";
69
+ export const EVENT_CTA_READY = "cta-ready";
70
+ export const EVENT_DONE = "done";
71
+ export const EVENT_ERROR = "error";
72
+ export const EVENT_PROTOCOL_UNSUPPORTED = "protocol-unsupported";
73
+ /** Every event name in the contract, in declaration order. */
74
+ export const WIRE_EVENTS = [
75
+ "theme-ready",
76
+ "cta-style-ready",
77
+ "experience-ready",
78
+ "layout-ready",
79
+ "background-ready",
80
+ "sequence-ready",
81
+ "video-ready",
82
+ "greeting-start",
83
+ "greeting-chunk",
84
+ "greeting-done",
85
+ "headline-start",
86
+ "headline-chunk",
87
+ "headline-done",
88
+ "body-start",
89
+ "body-chunk",
90
+ "body-done",
91
+ "cta-start",
92
+ "cta-chunk",
93
+ "cta-done",
94
+ "cta-ready",
95
+ "done",
96
+ "error",
97
+ "protocol-unsupported",
98
+ ];
99
+ /** Minimum protocol version each event may appear on. */
100
+ export const EVENT_SINCE = {
101
+ "theme-ready": 1,
102
+ "cta-style-ready": 1,
103
+ "experience-ready": 1,
104
+ "layout-ready": 1,
105
+ "background-ready": 1,
106
+ "sequence-ready": 1,
107
+ "video-ready": 1,
108
+ "greeting-start": 1,
109
+ "greeting-chunk": 1,
110
+ "greeting-done": 1,
111
+ "headline-start": 1,
112
+ "headline-chunk": 1,
113
+ "headline-done": 1,
114
+ "body-start": 1,
115
+ "body-chunk": 1,
116
+ "body-done": 1,
117
+ "cta-start": 1,
118
+ "cta-chunk": 1,
119
+ "cta-done": 1,
120
+ "cta-ready": 1,
121
+ "done": 1,
122
+ "error": 1,
123
+ "protocol-unsupported": 2,
124
+ };
125
+ /**
126
+ * Is this an event name the contract knows? An unknown event on the wire is
127
+ * not an error — a newer server may emit events this client predates — but
128
+ * it must be ignored, not guessed at.
129
+ */
130
+ export function isWireEvent(name) {
131
+ return WIRE_EVENTS.includes(name);
132
+ }
133
+ //# sourceMappingURL=wire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EAAE,CAAC;IAClB,YAAY,EAAE,CAAC;IACf,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,CAAC;IACd,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,CAAC;IACd,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,sBAAsB,EAAE,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAQ,WAAiC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@sparkletree/core",
3
+ "version": "0.1.0",
4
+ "description": "Framework-agnostic core for the SparkleTree SDK: wire protocol, copy choreography, theme, analytics, audio.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "LICENSE",
19
+ "README.md"
20
+ ],
21
+ "devDependencies": {
22
+ "typescript": "^5.9.2",
23
+ "vitest": "^3.2.4"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://gitlab.com/sparkletree/sparkletree-sdk.git",
31
+ "directory": "core"
32
+ },
33
+ "author": "SparkleTree",
34
+ "homepage": "https://gitlab.com/sparkletree/sparkletree-sdk/-/blob/main/README.md",
35
+ "bugs": {
36
+ "url": "https://gitlab.com/sparkletree/sparkletree-sdk/-/issues"
37
+ },
38
+ "keywords": [
39
+ "sparkletree",
40
+ "adaptive",
41
+ "personalization",
42
+ "sse",
43
+ "streaming",
44
+ "creative"
45
+ ],
46
+ "engines": {
47
+ "node": ">=18"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc --project tsconfig.json",
51
+ "clean": "rm -rf dist",
52
+ "test": "vitest run",
53
+ "typecheck": "tsc --project tsconfig.json --noEmit"
54
+ }
55
+ }