@rep-protocol/svelte 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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Specification documents (spec/, schema/) are licensed under:
2
+ Creative Commons Attribution 4.0 International (CC BY 4.0)
3
+ https://creativecommons.org/licenses/by/4.0/
4
+
5
+ Reference implementations and tooling are licensed under:
6
+ Apache License, Version 2.0
7
+ https://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Copyright 2026 Ruach Tech
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @rep-protocol/svelte
2
+
3
+ Svelte stores for the [Runtime Environment Protocol](https://github.com/ruachtech/rep).
4
+
5
+ Provides `repStore()` and `repSecureStore()` which wrap the REP SDK into Svelte-native readable stores. Subscribes to hot-reload updates automatically; the SSE connection is closed when all subscribers unsubscribe.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @rep-protocol/svelte @rep-protocol/sdk
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```svelte
16
+ <script lang="ts">
17
+ import { repStore, repSecureStore } from '@rep-protocol/svelte';
18
+
19
+ // PUBLIC tier — synchronous initial value, updates on hot reload.
20
+ const apiUrl = repStore('API_URL', 'http://localhost:3000');
21
+ const flags = repStore('FEATURE_FLAGS', '');
22
+
23
+ // SENSITIVE tier — starts as null, resolves after session key fetch.
24
+ const analyticsKey = repSecureStore('ANALYTICS_KEY');
25
+ </script>
26
+
27
+ <p>API: {$apiUrl}</p>
28
+ <p>Analytics: {$analyticsKey ?? 'loading…'}</p>
29
+ ```
30
+
31
+ ## API
32
+
33
+ ### `repStore(key, defaultValue?)`
34
+
35
+ Reads a **PUBLIC** tier variable as a Svelte `Readable<string | undefined>`.
36
+
37
+ ```typescript
38
+ const value: Readable<string | undefined> = repStore('API_URL');
39
+ const value: Readable<string | undefined> = repStore('API_URL', 'fallback');
40
+ ```
41
+
42
+ - Synchronous initial value — set immediately from the REP payload.
43
+ - Returns `defaultValue` (or `undefined`) if the variable is not present.
44
+ - Automatically updates when the variable changes via hot reload.
45
+ - **Lazy:** the SSE subscription is established only when there is at least one subscriber. The connection is closed when all subscribers unsubscribe.
46
+
47
+ ### `repSecureStore(key)`
48
+
49
+ Reads a **SENSITIVE** tier variable as a Svelte `Readable<string | null>`.
50
+
51
+ ```typescript
52
+ const value: Readable<string | null> = repSecureStore('ANALYTICS_KEY');
53
+ ```
54
+
55
+ - Starts as `null`.
56
+ - Resolves to the decrypted value once the session key fetch completes.
57
+ - The decrypted value is cached by the SDK for the page lifetime.
58
+ - Errors are swallowed silently (the SDK logs them); the store stays `null`.
59
+
60
+ ## Hot Reload
61
+
62
+ `repStore` subscribes to the REP gateway's SSE stream lazily (on first `subscribe()` call). The store updates automatically when config changes. The SSE connection is closed when there are no remaining subscribers.
63
+
64
+ `repSecureStore` does not support hot reload — changes to sensitive variables require a page reload.
65
+
66
+ ## Requirements
67
+
68
+ - Svelte ≥ 4 or Svelte 5
69
+ - `@rep-protocol/sdk` as a peer dependency
70
+
71
+ ## Development Mode
72
+
73
+ Without the REP gateway, `repStore()` returns a store with value `undefined`. Use `defaultValue` for local development:
74
+
75
+ ```typescript
76
+ const apiUrl = repStore('API_URL', 'http://localhost:3000');
77
+ ```
78
+
79
+ Or inject a mock payload in your `index.html`:
80
+
81
+ ```html
82
+ <script id="__rep__" type="application/json">
83
+ {"public":{"API_URL":"http://localhost:3000"},"_meta":{"version":"0.1.0","injected_at":"2026-01-01T00:00:00Z","integrity":"hmac-sha256:dev","ttl":0}}
84
+ </script>
85
+ ```
86
+
87
+ ## Specification
88
+
89
+ Implements [REP-RFC-0001 §5.5 — Framework Adapters](https://github.com/ruachtech/rep/blob/main/spec/REP-RFC-0001.md).
90
+
91
+ ## License
92
+
93
+ Apache 2.0
@@ -0,0 +1,43 @@
1
+ import { Readable } from 'svelte/store';
2
+
3
+ /**
4
+ * @rep-protocol/svelte — Svelte stores for the Runtime Environment Protocol.
5
+ *
6
+ * Provides `repStore()` and `repSecureStore()` which wrap the SDK into
7
+ * Svelte-native readable stores. Subscribers receive hot-reload updates
8
+ * automatically; the SSE connection is closed when all subscribers unsub.
9
+ *
10
+ * @see https://github.com/ruachtech/rep — REP-RFC-0001 §5.5
11
+ * @license Apache-2.0
12
+ * @version 0.1.0
13
+ */
14
+
15
+ /**
16
+ * A readable store for a PUBLIC tier variable. Synchronous initial value.
17
+ *
18
+ * The store updates whenever the variable changes via hot reload.
19
+ * The underlying SSE connection is cleaned up when all subscribers unsubscribe.
20
+ *
21
+ * @param key Variable name (without `REP_PUBLIC_` prefix).
22
+ * @param defaultValue Fallback value if the variable is not present.
23
+ *
24
+ * @example
25
+ * const apiUrl = repStore('API_URL', 'https://api.example.com');
26
+ * $: console.log($apiUrl);
27
+ */
28
+ declare function repStore(key: string, defaultValue?: string): Readable<string | undefined>;
29
+ /**
30
+ * A readable store for a SENSITIVE tier variable. Starts as `null`, resolves async.
31
+ *
32
+ * Fetches the session key on first subscription and decrypts the value.
33
+ * The decrypted value is cached by the SDK for the page lifetime.
34
+ *
35
+ * @param key Variable name (without `REP_SENSITIVE_` prefix).
36
+ *
37
+ * @example
38
+ * const analyticsKey = repSecureStore('ANALYTICS_KEY');
39
+ * $: console.log($analyticsKey); // null initially, then the decrypted value
40
+ */
41
+ declare function repSecureStore(key: string): Readable<string | null>;
42
+
43
+ export { repSecureStore, repStore };
@@ -0,0 +1,43 @@
1
+ import { Readable } from 'svelte/store';
2
+
3
+ /**
4
+ * @rep-protocol/svelte — Svelte stores for the Runtime Environment Protocol.
5
+ *
6
+ * Provides `repStore()` and `repSecureStore()` which wrap the SDK into
7
+ * Svelte-native readable stores. Subscribers receive hot-reload updates
8
+ * automatically; the SSE connection is closed when all subscribers unsub.
9
+ *
10
+ * @see https://github.com/ruachtech/rep — REP-RFC-0001 §5.5
11
+ * @license Apache-2.0
12
+ * @version 0.1.0
13
+ */
14
+
15
+ /**
16
+ * A readable store for a PUBLIC tier variable. Synchronous initial value.
17
+ *
18
+ * The store updates whenever the variable changes via hot reload.
19
+ * The underlying SSE connection is cleaned up when all subscribers unsubscribe.
20
+ *
21
+ * @param key Variable name (without `REP_PUBLIC_` prefix).
22
+ * @param defaultValue Fallback value if the variable is not present.
23
+ *
24
+ * @example
25
+ * const apiUrl = repStore('API_URL', 'https://api.example.com');
26
+ * $: console.log($apiUrl);
27
+ */
28
+ declare function repStore(key: string, defaultValue?: string): Readable<string | undefined>;
29
+ /**
30
+ * A readable store for a SENSITIVE tier variable. Starts as `null`, resolves async.
31
+ *
32
+ * Fetches the session key on first subscription and decrypts the value.
33
+ * The decrypted value is cached by the SDK for the page lifetime.
34
+ *
35
+ * @param key Variable name (without `REP_SENSITIVE_` prefix).
36
+ *
37
+ * @example
38
+ * const analyticsKey = repSecureStore('ANALYTICS_KEY');
39
+ * $: console.log($analyticsKey); // null initially, then the decrypted value
40
+ */
41
+ declare function repSecureStore(key: string): Readable<string | null>;
42
+
43
+ export { repSecureStore, repStore };
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ repSecureStore: () => repSecureStore,
24
+ repStore: () => repStore
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_store = require("svelte/store");
28
+ var import_sdk = require("@rep-protocol/sdk");
29
+ function repStore(key, defaultValue) {
30
+ return (0, import_store.readable)((0, import_sdk.get)(key, defaultValue), (set) => {
31
+ const unsubscribe = (0, import_sdk.onChange)(key, (newValue) => {
32
+ set(newValue !== "" ? newValue : defaultValue);
33
+ });
34
+ return unsubscribe;
35
+ });
36
+ }
37
+ function repSecureStore(key) {
38
+ return (0, import_store.readable)(null, (set) => {
39
+ (0, import_sdk.getSecure)(key).then((v) => set(v)).catch(() => {
40
+ });
41
+ return () => {
42
+ };
43
+ });
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ repSecureStore,
48
+ repStore
49
+ });
50
+ /**
51
+ * @rep-protocol/svelte — Svelte stores for the Runtime Environment Protocol.
52
+ *
53
+ * Provides `repStore()` and `repSecureStore()` which wrap the SDK into
54
+ * Svelte-native readable stores. Subscribers receive hot-reload updates
55
+ * automatically; the SSE connection is closed when all subscribers unsub.
56
+ *
57
+ * @see https://github.com/ruachtech/rep — REP-RFC-0001 §5.5
58
+ * @license Apache-2.0
59
+ * @version 0.1.0
60
+ */
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ // src/index.ts
2
+ import { readable } from "svelte/store";
3
+ import { get, getSecure, onChange } from "@rep-protocol/sdk";
4
+ function repStore(key, defaultValue) {
5
+ return readable(get(key, defaultValue), (set) => {
6
+ const unsubscribe = onChange(key, (newValue) => {
7
+ set(newValue !== "" ? newValue : defaultValue);
8
+ });
9
+ return unsubscribe;
10
+ });
11
+ }
12
+ function repSecureStore(key) {
13
+ return readable(null, (set) => {
14
+ getSecure(key).then((v) => set(v)).catch(() => {
15
+ });
16
+ return () => {
17
+ };
18
+ });
19
+ }
20
+ export {
21
+ repSecureStore,
22
+ repStore
23
+ };
24
+ /**
25
+ * @rep-protocol/svelte — Svelte stores for the Runtime Environment Protocol.
26
+ *
27
+ * Provides `repStore()` and `repSecureStore()` which wrap the SDK into
28
+ * Svelte-native readable stores. Subscribers receive hot-reload updates
29
+ * automatically; the SSE connection is closed when all subscribers unsub.
30
+ *
31
+ * @see https://github.com/ruachtech/rep — REP-RFC-0001 §5.5
32
+ * @license Apache-2.0
33
+ * @version 0.1.0
34
+ */
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@rep-protocol/svelte",
3
+ "version": "0.1.1",
4
+ "description": "Svelte adapter for the Runtime Environment Protocol (REP).",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "peerDependencies": {
12
+ "svelte": "^4.0.0 || ^5.0.0",
13
+ "@rep-protocol/sdk": "0.1.2"
14
+ },
15
+ "devDependencies": {
16
+ "svelte": "^4.2.0",
17
+ "tsup": "^8.0.0",
18
+ "typescript": "^5.4.0",
19
+ "vitest": "^1.6.0"
20
+ },
21
+ "scripts": {
22
+ "build": "tsup src/index.ts --format cjs,esm --dts",
23
+ "test": "vitest run"
24
+ }
25
+ }