@strifeapp/astro 1.0.29 → 1.2.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.
@@ -0,0 +1,143 @@
1
+ import { readFileSync as l } from "fs";
2
+ import { dirname as f, resolve as u } from "path";
3
+ import { fileURLToPath as d } from "url";
4
+ import r from "serialize-javascript";
5
+ const s = "strife:store", o = "\0" + s;
6
+ function h(i) {
7
+ const n = d(import.meta.url), a = f(n), c = l(
8
+ u(a, "./localized-content-index.js"),
9
+ "utf-8"
10
+ ), e = { ...i };
11
+ return delete e.certificate, delete e.password, {
12
+ name: "strife:store",
13
+ resolveId(t) {
14
+ if (t === s)
15
+ return o;
16
+ },
17
+ load(t) {
18
+ if (t === o)
19
+ return `
20
+ import { DocumentStore, AbstractJavaScriptMultiMapIndexCreationTask } from "ravendb";
21
+ import { getSecret } from "astro:env/server";
22
+
23
+ const indexMappingSource = ${r(c)};
24
+ const defaultConfig = ${r(e)};
25
+
26
+ // --- STRIFE_SECRET decode (keep in sync with src/secrets-codec.ts; format v1.<meta>.<cert>) ---
27
+ function decodeStrifeSecrets(value) {
28
+ const sections = value.split('.');
29
+ if (sections.length !== 3) {
30
+ throw new Error('STRIFE_SECRET: expected 3 dot-separated sections, got ' + sections.length);
31
+ }
32
+ const version = sections[0];
33
+ if (version !== 'v1') {
34
+ if (/^v\\d+$/.test(version)) return null; // known-shape future version -> treat as unset
35
+ throw new Error('STRIFE_SECRET: unrecognised format (missing version prefix)');
36
+ }
37
+ const b64url = /^[A-Za-z0-9_-]+$/;
38
+ if (!b64url.test(sections[1])) throw new Error('STRIFE_SECRET: meta section is not valid base64url');
39
+ if (!b64url.test(sections[2])) throw new Error('STRIFE_SECRET: cert section is not valid base64url');
40
+ let meta;
41
+ try {
42
+ meta = JSON.parse(Buffer.from(sections[1], 'base64url').toString('utf8'));
43
+ } catch (e) {
44
+ throw new Error('STRIFE_SECRET: meta section is not valid JSON'); // never echo the (secret) content
45
+ }
46
+ if (typeof meta !== 'object' || meta === null || !Array.isArray(meta.urls) || typeof meta.database !== 'string') {
47
+ throw new Error('STRIFE_SECRET: meta section missing required fields (urls, database)');
48
+ }
49
+ return {
50
+ urls: meta.urls,
51
+ database: meta.database,
52
+ password: meta.password,
53
+ type: meta.type,
54
+ certificate: Buffer.from(sections[2], 'base64url'), // raw PFX bytes, decoded once
55
+ };
56
+ }
57
+
58
+ const strifeSecretsBlob = getSecret('STRIFE_SECRET');
59
+ // null = known-shape future version -> treat as unset and fall back to the four vars.
60
+ const secrets = strifeSecretsBlob ? (decodeStrifeSecrets(strifeSecretsBlob) || {}) : {};
61
+
62
+ // Resolution priority: STRIFE_SECRET field -> individual STRIFE_* var -> integration option.
63
+ // Operator pinned to || with an empty string treated as unset (matches prior behaviour).
64
+ const urlsFromEnv = getSecret('STRIFE_DATABASE_URLS');
65
+ const urls = (secrets.urls && secrets.urls.length)
66
+ ? secrets.urls
67
+ : (urlsFromEnv ? urlsFromEnv.split(',') : (defaultConfig.urls || []));
68
+
69
+ const database = secrets.database || getSecret('STRIFE_DATABASE') || defaultConfig.database || '';
70
+
71
+ // From the blob the certificate is already raw PFX bytes (Buffer); from an env var or
72
+ // option it is a base64 string, decoded once here. Normalise to a Buffer either way.
73
+ let certificate;
74
+ if (secrets.certificate) {
75
+ certificate = secrets.certificate;
76
+ } else {
77
+ const certBase64 = getSecret('STRIFE_CERTIFICATE') || defaultConfig.certificate;
78
+ certificate = certBase64 ? Buffer.from(certBase64, 'base64') : undefined;
79
+ }
80
+
81
+ const password = secrets.password || getSecret('STRIFE_CERTIFICATE_PASSWORD') || defaultConfig.password;
82
+
83
+ // R9: a certificate without a password must not silently initialise an unauthenticated store.
84
+ if (certificate && !password) {
85
+ throw new Error('STRIFE_SECRET: a certificate was provided without a password (set STRIFE_CERTIFICATE_PASSWORD or include the password in STRIFE_SECRET)');
86
+ }
87
+
88
+ const hasAuth = certificate && password;
89
+
90
+ const authOptions = hasAuth ? {
91
+ type: secrets.type || defaultConfig.type || 'pfx',
92
+ certificate: certificate,
93
+ password,
94
+ } : null;
95
+
96
+ const store = new DocumentStore(
97
+ urls,
98
+ database,
99
+ authOptions || undefined,
100
+ ).initialize();
101
+
102
+ class Content_ByUrl extends AbstractJavaScriptMultiMapIndexCreationTask {
103
+ constructor() {
104
+ super();
105
+
106
+ this.additionalSources = {"Helper": indexMappingSource};
107
+
108
+ const collections = (defaultConfig.collections && defaultConfig.collections.length)
109
+ ? defaultConfig.collections
110
+ : ['Posts'];
111
+
112
+ for (const collection of collections) {
113
+ const name = typeof collection === 'string' ? collection : collection.name;
114
+ this.map(name, function (doc) { return mapDocument(doc); });
115
+ }
116
+
117
+ this.deploymentMode = 'Rolling';
118
+ this.searchEngineType = 'Lucene';
119
+ }
120
+ }
121
+
122
+ console.log('Deploying index...');
123
+
124
+ await store.executeIndex(new Content_ByUrl());
125
+
126
+ const bulkInsert = store.bulkInsert();
127
+
128
+ if (defaultConfig.collections && defaultConfig.collections.length) {
129
+ for (const collection of defaultConfig.collections) {
130
+ await bulkInsert.store(collection, 'templates/' + collection.name, { '@collection': 'Templates' });
131
+ }
132
+ }
133
+
134
+ await bulkInsert.finish();
135
+
136
+ export { store };
137
+ `;
138
+ }
139
+ };
140
+ }
141
+ export {
142
+ h as v
143
+ };
@@ -1,4 +1,4 @@
1
- import { v as t } from "./vite-plugin-strife-store-HEEze8Mw.js";
1
+ import { v as t } from "./vite-plugin-strife-store-Tvau120y.js";
2
2
  export {
3
3
  t as vitePluginStrifeStore
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-strife-store.d.ts","sourceRoot":"","sources":["../src/vite-plugin-strife-store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAKlD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAmE9E"}
1
+ {"version":3,"file":"vite-plugin-strife-store.d.ts","sourceRoot":"","sources":["../src/vite-plugin-strife-store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAKlD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAqJ9E"}
package/package.json CHANGED
@@ -1,47 +1,80 @@
1
1
  {
2
2
  "name": "@strifeapp/astro",
3
- "version": "1.0.29",
4
- "description": "Official Strife Astro integration",
3
+ "version": "1.2.0",
4
+ "description": "Official Strife integration for Astro — connect your Astro site to a RavenDB-backed Strife content store via a strife:store virtual module.",
5
5
  "keywords": [
6
6
  "astro-integration",
7
7
  "withastro",
8
- "strife"
8
+ "astro-component",
9
+ "strife",
10
+ "ravendb",
11
+ "cms",
12
+ "headless-cms"
9
13
  ],
14
+ "homepage": "https://github.com/wieldyapp/wieldy/tree/master/src/sdk/js/src/packages/astro#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/wieldyapp/wieldy/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/wieldyapp/wieldy.git",
21
+ "directory": "src/sdk/js/src/packages/astro"
22
+ },
23
+ "license": "ISC",
24
+ "author": "Strife (https://strife.app)",
25
+ "type": "module",
10
26
  "main": "./dist/index.js",
11
27
  "module": "./dist/index.js",
12
28
  "types": "./dist/index.d.ts",
13
- "type": "module",
14
- "scripts": {
15
- "clean": "rm -rf dist",
16
- "build": "npm run clean && vite build",
17
- "prepublishOnly": "npm run build"
18
- },
19
29
  "exports": {
20
30
  ".": {
21
- "import": "./dist/index.js",
22
- "types": "./dist/index.d.ts"
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
23
33
  },
24
- "./vite-plugin-strife-store": "./dist/vite-plugin-strife-store-entry.js",
25
- "./module": "./module.d.ts"
34
+ "./edit-mode": {
35
+ "types": "./dist/edit-mode.d.ts",
36
+ "import": "./dist/edit-mode.js"
37
+ },
38
+ "./edit-mode-middleware": {
39
+ "types": "./dist/edit-mode-middleware.d.ts",
40
+ "import": "./dist/edit-mode-middleware.js"
41
+ },
42
+ "./LivePreview.astro": "./dist/LivePreview.astro",
43
+ "./vite-plugin-strife-store": "./dist/vite-plugin-strife-store-entry.js"
26
44
  },
27
45
  "files": [
28
46
  "dist"
29
47
  ],
48
+ "engines": {
49
+ "node": ">=22.12.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "scripts": {
55
+ "clean": "rm -rf dist",
56
+ "build": "npm run clean && vite build",
57
+ "typecheck": "tsc --noEmit",
58
+ "test": "vitest run",
59
+ "prepublishOnly": "npm run build"
60
+ },
30
61
  "dependencies": {
31
- "astro": "^4.0.0 || ^5.0.0",
62
+ "@strifeapp/strife": "^1.0.1",
32
63
  "dotenv": "^17.2.3",
64
+ "jose": "^5.9.6",
33
65
  "ravendb": "^7.1.4",
34
66
  "serialize-javascript": "^6.0.2"
35
67
  },
36
68
  "devDependencies": {
37
- "@types/dotenv": "^8.2.0",
38
69
  "@types/serialize-javascript": "^5.0.4",
70
+ "astro": "^6.3.6",
39
71
  "rimraf": "^6.0.1",
40
72
  "typescript": "^5.7.3",
41
- "vite": "^6.4.1",
42
- "vite-plugin-dts": "^4.5.3"
73
+ "vite": "^7.0.0",
74
+ "vite-plugin-dts": "^4.5.3",
75
+ "vitest": "^4.1.7"
43
76
  },
44
77
  "peerDependencies": {
45
- "astro": "^4.0.0 || ^5.0.0"
78
+ "astro": "^5.0.0 || ^6.0.0"
46
79
  }
47
80
  }
@@ -1,73 +0,0 @@
1
- import { readFileSync as c } from "fs";
2
- import { dirname as m, resolve as u } from "path";
3
- import { fileURLToPath as d } from "url";
4
- import r from "serialize-javascript";
5
- const n = "strife:store", o = "\0" + n;
6
- function S(e) {
7
- const i = d(import.meta.url), p = m(i), l = c(
8
- u(p, "./localized-content-index.js"),
9
- "utf-8"
10
- );
11
- return {
12
- name: "strife:store",
13
- resolveId(s) {
14
- if (s === n)
15
- return o;
16
- },
17
- load(s) {
18
- var a;
19
- if (s === o)
20
- return `
21
- import { DocumentStore, AbstractJavaScriptMultiMapIndexCreationTask } from "ravendb";
22
-
23
- ${e.certificate && e.password ? `
24
- const authOptions = {
25
- type: 'pfx',
26
- certificate: Buffer.from(${r(e.certificate)}, 'base64'),
27
- password: ${r(e.password)},
28
- };
29
- ` : ""}
30
-
31
- const store = new DocumentStore(
32
- ${r(e.urls ? e.urls : [])},
33
- ${r(e.database || "")}${e.certificate && e.password ? `,
34
- authOptions` : ""}
35
- ).initialize()
36
-
37
- class Content_ByUrl extends AbstractJavaScriptMultiMapIndexCreationTask {
38
- constructor() {
39
- super();
40
-
41
- this.additionalSources = {"Helper": ${r(l)}}
42
-
43
- ${(e.collections || ["Posts"]).map(
44
- (t) => `this.map("${typeof t == "string" ? t : t.name}", (doc) => { return mapDocument(doc) });`
45
- ).join(`
46
- `)}
47
-
48
- this.deploymentMode = 'Rolling';
49
- this.searchEngineType = 'Lucene';
50
- }
51
- }
52
-
53
- console.log('Deploying index...');
54
-
55
- await store.executeIndex(new Content_ByUrl());
56
-
57
- const bulkInsert = store.bulkInsert();
58
-
59
- ${(a = e.collections) == null ? void 0 : a.map((t) => `
60
- await bulkInsert.store(${JSON.stringify(t)}, 'templates/${t.name}', { '@collection': 'Templates' });
61
- `).join(`
62
- `)}
63
-
64
- await bulkInsert.finish();
65
-
66
- export { store };
67
- `;
68
- }
69
- };
70
- }
71
- export {
72
- S as v
73
- };