@faith-tools/bible-sdk 0.6.0 → 0.7.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/README.md +57 -8
- package/dist/bible-sdk.js +1 -1
- package/dist/data/effect.js +4 -3
- package/dist/data.js +1 -1
- package/dist/index.js +1 -1
- package/dist/providers/api-bible.js +221 -0
- package/dist/providers/fetch-bible.js +1 -1
- package/dist/providers/helloao.js +1 -1
- package/dist/providers/youversion.js +1 -1
- package/dist/{providers-D_4UrThl.js → providers-Ci0Bdu9f.js} +1 -1
- package/dist/{runtime-C-BCRjZd.js → runtime-CVlBLU4v.js} +16 -7
- package/dist/scripture-inline.js +1 -1
- package/dist/types/data-effect.d.ts +22 -0
- package/dist/types/data-helpers.d.ts +2 -2
- package/dist/types/data-types.d.ts +14 -1
- package/dist/types/data.d.ts +11 -0
- package/dist/types/providers/api-bible.d.ts +37 -0
- package/package.json +7 -1
package/dist/data/effect.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as e } from "../providers-
|
|
2
|
-
import { _ as t, b as n, g as r, h as i, l as a, m as o, n as s, p as c, r as l, s as u, t as d, u as f, v as p, y as m } from "../runtime-
|
|
1
|
+
import { t as e } from "../providers-Ci0Bdu9f.js";
|
|
2
|
+
import { _ as t, b as n, g as r, h as i, l as a, m as o, n as s, p as c, r as l, s as u, t as d, u as f, v as p, y as m } from "../runtime-CVlBLU4v.js";
|
|
3
3
|
import { Effect as h, Layer as g, Schema as _ } from "effect";
|
|
4
4
|
// src/data-effect.ts
|
|
5
5
|
var v = _.NonEmptyString.check(_.isTrimmed()), y = (e, t) => _.decodeUnknownEffect(v)(t ?? e.defaultVersionId).pipe(h.mapError((e) => new p({
|
|
@@ -39,9 +39,10 @@ function x({ provider: t = e() } = {}) {
|
|
|
39
39
|
listChapters: n,
|
|
40
40
|
getPassageData: n,
|
|
41
41
|
clearCache: h.void
|
|
42
|
-
}, u = f(), d = g.succeed(i, {
|
|
42
|
+
}, u = f(a.cacheTimeToLive), d = g.succeed(i, {
|
|
43
43
|
id: a.id,
|
|
44
44
|
defaultVersionId: a.defaultVersionId,
|
|
45
|
+
cacheTimeToLive: a.cacheTimeToLive,
|
|
45
46
|
listVersions: () => u.get("versions", () => a.listVersions().pipe(h.tap(s(_.Array(r))))),
|
|
46
47
|
listBooks: (e) => u.get(JSON.stringify(["books", e]), () => a.listBooks(e).pipe(h.tap(s(_.Array(c))))),
|
|
47
48
|
listChapters: (e, t) => u.get(JSON.stringify([
|
package/dist/data.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s } from "./providers-
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s } from "./providers-Ci0Bdu9f.js";
|
|
2
2
|
import { OSIS_BOOK_CODES as c, OSIS_BOOK_NAMES as l, autocompletePassage as u, formatPassageForDisplay as d, getChapterCount as f, getVerseCount as p, parsePassage as m, parseToResolverUrl as h, resolveBookAlias as g, tryParsePassage as _ } from "grab-bcv";
|
|
3
3
|
import { Effect as v, Exit as y, Scope as b } from "effect";
|
|
4
4
|
// src/dom-runtime.ts
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { a as e, d as t, l as n, r, s as i, u as a, v as o } from "../runtime-CVlBLU4v.js";
|
|
2
|
+
import { Clock as s, Effect as c, Schema as l } from "effect";
|
|
3
|
+
// src/providers/api-bible.ts
|
|
4
|
+
var u = {
|
|
5
|
+
contentType: "json",
|
|
6
|
+
includeTitles: !0,
|
|
7
|
+
includeNotes: !1,
|
|
8
|
+
includeChapterNumbers: !1,
|
|
9
|
+
includeVerseNumbers: !1
|
|
10
|
+
}, d = "https://api.bible/", f = "https://api.bible/terms-and-conditions", p = "14 days", m = 12096e5, h = l.optional(l.NullOr(l.String)), g = l.Struct({
|
|
11
|
+
id: l.NonEmptyString,
|
|
12
|
+
name: l.String,
|
|
13
|
+
nameLocal: h,
|
|
14
|
+
abbreviation: l.String,
|
|
15
|
+
abbreviationLocal: h,
|
|
16
|
+
language: l.Struct({
|
|
17
|
+
id: e,
|
|
18
|
+
name: l.String,
|
|
19
|
+
scriptDirection: h
|
|
20
|
+
}),
|
|
21
|
+
copyright: h,
|
|
22
|
+
info: h
|
|
23
|
+
}), _ = l.Struct({
|
|
24
|
+
style: l.optional(l.String),
|
|
25
|
+
verseId: l.optional(l.String)
|
|
26
|
+
}), v = l.suspend(() => l.Union([l.Struct({
|
|
27
|
+
type: l.Literal("text"),
|
|
28
|
+
text: l.String,
|
|
29
|
+
attrs: l.optional(_)
|
|
30
|
+
}), l.Struct({
|
|
31
|
+
type: l.Literal("tag"),
|
|
32
|
+
name: l.String,
|
|
33
|
+
attrs: l.optional(_),
|
|
34
|
+
items: l.Array(v)
|
|
35
|
+
})])), y = l.Struct({
|
|
36
|
+
data: l.Struct({
|
|
37
|
+
id: l.NonEmptyString,
|
|
38
|
+
bibleId: l.NonEmptyString,
|
|
39
|
+
reference: l.NonEmptyString,
|
|
40
|
+
copyright: l.NonEmptyString,
|
|
41
|
+
content: l.Array(v)
|
|
42
|
+
}),
|
|
43
|
+
meta: l.Struct({ fumsToken: l.NonEmptyString })
|
|
44
|
+
}), b = (e) => ({
|
|
45
|
+
id: e.id,
|
|
46
|
+
title: e.nameLocal || e.name,
|
|
47
|
+
abbreviation: e.abbreviationLocal || e.abbreviation,
|
|
48
|
+
language: new Intl.Locale(e.language.id).language,
|
|
49
|
+
languageName: e.language.name
|
|
50
|
+
}), x = () => new o({
|
|
51
|
+
code: "invalid_response",
|
|
52
|
+
message: "API.Bible returned incomplete or inconsistent passage data."
|
|
53
|
+
}), S = (e) => (t) => l.decodeUnknownEffect(e)(t).pipe(c.mapError(x)), C = (e) => {
|
|
54
|
+
let t = l.decodeUnknownOption(l.Struct({ statusCode: l.Number }))(e), n = l.decodeUnknownOption(l.Struct({ name: l.String }))(e), r = t._tag === "Some" ? t.value.statusCode : 0, i = n._tag === "Some" && n.value.name === "ValidationError" ? "invalid_response" : r === 401 || r === 403 ? "authentication" : r === 429 ? "rate_limit" : r >= 400 && r < 500 ? "unavailable" : "network";
|
|
55
|
+
return new o({
|
|
56
|
+
code: i,
|
|
57
|
+
message: `API.Bible request failed (${i}).`
|
|
58
|
+
});
|
|
59
|
+
}, w = (e, t) => r(e, async (e) => {
|
|
60
|
+
try {
|
|
61
|
+
return await t(e);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
throw C(e);
|
|
64
|
+
}
|
|
65
|
+
}), T = (e) => e.replace(/^([A-Z0-9]{3}\.[1-9]\d*\.)([1-9]\d*)-\1([1-9]\d*)$/, "$1$2-$3");
|
|
66
|
+
function E(e) {
|
|
67
|
+
let t = /* @__PURE__ */ new Set(), n = (e) => {
|
|
68
|
+
if (e.type === "text") return e.attrs?.verseId && t.add(e.attrs.verseId), e.text;
|
|
69
|
+
let r = e.attrs?.style ?? "";
|
|
70
|
+
if (e.name === "note" || e.name === "verse" || e.name === "chapter" || /^(?:s\d*|sp|qa|ms\d*|mr|r|sr|mt\d*|mte\d*|cl|cp|cd|v|c|f\w*|x\w*)$/.test(r)) return "";
|
|
71
|
+
let i = e.items.map(n).join("");
|
|
72
|
+
return e.name === "para" ? i + (/^q[rmc]?\d*$/.test(r) ? "\n" : "\n\n") : i;
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
text: e.map(n).join("").replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim(),
|
|
76
|
+
verseIds: t
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function D({ client: e, defaultVersionId: r }) {
|
|
80
|
+
if (typeof window < "u") throw new o({
|
|
81
|
+
code: "unsupported",
|
|
82
|
+
message: "API.Bible requires a server-side client. Never expose its private key in a browser."
|
|
83
|
+
});
|
|
84
|
+
let h = a(p), _ = (t) => h.get(t, () => c.gen(function* () {
|
|
85
|
+
let n = yield* s.currentTimeMillis, { data: r } = yield* w("apiBible.version", (n) => e.bibles.get(t, n)).pipe(c.flatMap(S(l.Struct({ data: g }))));
|
|
86
|
+
return r.id !== t || !r.copyright?.trim() ? yield* x() : {
|
|
87
|
+
data: r,
|
|
88
|
+
expiresAt: n + m
|
|
89
|
+
};
|
|
90
|
+
}));
|
|
91
|
+
return {
|
|
92
|
+
id: "api-bible",
|
|
93
|
+
defaultVersionId: r,
|
|
94
|
+
cacheTimeToLive: p,
|
|
95
|
+
clearCache: h.clear,
|
|
96
|
+
listVersions: c.fn("apiBible.listVersions")(function* () {
|
|
97
|
+
let { data: t } = yield* w("apiBible.versions", (t) => e.bibles.list({ includeFullDetails: !0 }, t)).pipe(c.flatMap(S(l.Struct({ data: l.Array(g) }))));
|
|
98
|
+
return t.map(b);
|
|
99
|
+
}),
|
|
100
|
+
listBooks: c.fn("apiBible.listBooks")(function* (t) {
|
|
101
|
+
let { data: n } = yield* w("apiBible.books", (n) => e.books.list(t, void 0, n)).pipe(c.flatMap(S(l.Struct({ data: l.Array(l.Struct({
|
|
102
|
+
id: l.NonEmptyString,
|
|
103
|
+
name: l.String
|
|
104
|
+
})) }))));
|
|
105
|
+
return n.map((e) => ({
|
|
106
|
+
id: e.id,
|
|
107
|
+
title: e.name
|
|
108
|
+
}));
|
|
109
|
+
}),
|
|
110
|
+
listChapters: c.fn("apiBible.listChapters")(function* (t, r) {
|
|
111
|
+
yield* i(r);
|
|
112
|
+
let { data: a } = yield* w("apiBible.chapters", (n) => e.chapters.list(t, r, n)).pipe(c.flatMap(S(l.Struct({ data: l.Array(l.Struct({
|
|
113
|
+
id: l.String,
|
|
114
|
+
number: l.String
|
|
115
|
+
})) })))), o = [];
|
|
116
|
+
for (let e of a) {
|
|
117
|
+
if (e.number === "intro") continue;
|
|
118
|
+
let t = yield* n(e.id).pipe(c.mapError(x));
|
|
119
|
+
if (t.book !== r || t.first !== void 0 || String(t.chapter) !== e.number) return yield* x();
|
|
120
|
+
o.push({
|
|
121
|
+
passageId: e.id,
|
|
122
|
+
number: t.chapter
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return o;
|
|
126
|
+
}),
|
|
127
|
+
getPassageData: c.fn("apiBible.getPassageData")(function* (r, i) {
|
|
128
|
+
let { book: a, chapter: s, first: l, last: p } = yield* n(i), { data: m, expiresAt: h } = yield* _(r), g = `${a}.${s}${l === void 0 ? "" : `.${l}${p === l ? "" : `-${a}.${s}.${p}`}`}`, { data: v, meta: C } = yield* w("apiBible.passage", (t) => l === void 0 ? e.chapters.get(r, g, u, t) : e.passages.get(r, g, u, t)).pipe(c.flatMap(S(y)));
|
|
129
|
+
if (v.bibleId !== r || T(v.id) !== T(g)) return yield* x();
|
|
130
|
+
let { text: D, verseIds: O } = E(v.content), k = [];
|
|
131
|
+
for (let e of O) {
|
|
132
|
+
let t = yield* n(T(e)).pipe(c.mapError(x));
|
|
133
|
+
if (t.book !== a || t.chapter !== s || t.first === void 0 || l !== void 0 && (t.first < l || t.last > p)) return yield* x();
|
|
134
|
+
k.push({
|
|
135
|
+
first: t.first,
|
|
136
|
+
last: t.last
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
let A = (e) => k.some((t) => t.first <= e && t.last >= e);
|
|
140
|
+
return !k.length || l !== void 0 && (!A(l) || !A(p)) ? yield* new o({
|
|
141
|
+
code: "unavailable",
|
|
142
|
+
message: "API.Bible did not return the requested coverage; passages may be limited to 200 verses."
|
|
143
|
+
}) : {
|
|
144
|
+
provider: "api-bible",
|
|
145
|
+
source: {
|
|
146
|
+
url: d,
|
|
147
|
+
versionId: r
|
|
148
|
+
},
|
|
149
|
+
requestedPassageId: i,
|
|
150
|
+
passageId: T(v.id),
|
|
151
|
+
reference: v.reference,
|
|
152
|
+
text: D,
|
|
153
|
+
version: {
|
|
154
|
+
...b(m),
|
|
155
|
+
sourceLanguage: m.language.id
|
|
156
|
+
},
|
|
157
|
+
attribution: {
|
|
158
|
+
text: `${v.copyright} · ${b(m).abbreviation} · Source: API.Bible`,
|
|
159
|
+
urls: [d, f]
|
|
160
|
+
},
|
|
161
|
+
publisher: {
|
|
162
|
+
copyrightHtml: m.copyright,
|
|
163
|
+
infoHtml: m.info ?? ""
|
|
164
|
+
},
|
|
165
|
+
reporting: {
|
|
166
|
+
kind: "api-bible-fums",
|
|
167
|
+
token: C.fumsToken
|
|
168
|
+
},
|
|
169
|
+
cache: { expiresAt: h },
|
|
170
|
+
licenses: [{ url: f }],
|
|
171
|
+
numbering: "unknown",
|
|
172
|
+
display: {
|
|
173
|
+
format: "text",
|
|
174
|
+
whitespace: "pre-wrap",
|
|
175
|
+
attributionPlacement: "after-passage",
|
|
176
|
+
direction: m.language.scriptDirection === "rtl" ? "rtl" : m.language.scriptDirection === "ltr" ? "ltr" : void 0,
|
|
177
|
+
language: b(m).language
|
|
178
|
+
},
|
|
179
|
+
instructions: [
|
|
180
|
+
...t(),
|
|
181
|
+
{
|
|
182
|
+
code: "api-bible-fums",
|
|
183
|
+
level: "required",
|
|
184
|
+
appliesTo: "all",
|
|
185
|
+
text: "For web displays, report reporting.token for each actual view, including cache hits. Fetching or prefetching is not a view. The host owns anonymous device/session identifiers and reporting; native-only exemptions do not cover web views.",
|
|
186
|
+
urls: ["https://care.api.bible/article/417-understanding-fums"]
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
code: "api-bible-publisher",
|
|
190
|
+
level: "required",
|
|
191
|
+
appliesTo: "all",
|
|
192
|
+
text: "Preserve publisher copyrightHtml and infoHtml on a linked copyright/about page and identify the translation in context. These fields are untrusted upstream HTML: sanitize before rendering, never insert them directly. Keep the visible API.Bible source link.",
|
|
193
|
+
urls: [f]
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
code: "api-bible-cache",
|
|
197
|
+
level: "required",
|
|
198
|
+
appliesTo: "all",
|
|
199
|
+
text: "cache.expiresAt is an epoch-millisecond refresh deadline, not permission for offline storage. Refresh downstream caches by that deadline. Never retain metadata or content over 30 days without refresh. Honor removal/revocation requests immediately or within their specified shorter deadline.",
|
|
200
|
+
urls: ["https://care.api.bible/article/401-caching-content", f]
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
code: "api-bible-usage",
|
|
204
|
+
level: "required",
|
|
205
|
+
appliesTo: "all",
|
|
206
|
+
text: "Each application needs its own private server key and applicable plan and translation licenses. The host must satisfy DRM, print/device/territory limits, content integrity, account agreements, and removal duties. A working key or this adapter does not establish compliance. Starter is noncommercial even for public-domain text.",
|
|
207
|
+
urls: [f]
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
code: "api-bible-ai",
|
|
211
|
+
level: "required",
|
|
212
|
+
appliesTo: "all",
|
|
213
|
+
text: "Do not send copyrighted or Creative Commons Scripture to an LLM as prompt context or training data without the required permissions. Public-domain runtime prompts are permitted; confirm training and audio/export permissions separately.",
|
|
214
|
+
urls: ["https://care.api.bible/article/405-express-licensing-faqs", f]
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
};
|
|
218
|
+
})
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
export { D as createApiBibleProvider };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, d as t, f as n, i as r, l as i, n as a, o, r as s, s as c, u as l, v as u } from "../runtime-
|
|
1
|
+
import { a as e, d as t, f as n, i as r, l as i, n as a, o, r as s, s as c, u as l, v as u } from "../runtime-CVlBLU4v.js";
|
|
2
2
|
import { Effect as d, Schema as f } from "effect";
|
|
3
3
|
import { FetchClient as p } from "@gracious.tech/fetch-client";
|
|
4
4
|
import m from "sanitize-html";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createHelloAOProvider, i as helloaoProvider } from "../providers-
|
|
1
|
+
export { t as createHelloAOProvider, i as helloaoProvider } from "../providers-Ci0Bdu9f.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as createYouVersionProvider } from "../providers-
|
|
1
|
+
export { n as createYouVersionProvider } from "../providers-Ci0Bdu9f.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, u, v as d } from "./runtime-
|
|
1
|
+
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, u, v as d } from "./runtime-CVlBLU4v.js";
|
|
2
2
|
import { Effect as f, Schema as p } from "effect";
|
|
3
3
|
import { FreeUseBibleApi as m } from "free-use-bible-api";
|
|
4
4
|
// src/providers.ts
|
|
@@ -44,6 +44,15 @@ var s = o.Struct({
|
|
|
44
44
|
text: o.NonEmptyString,
|
|
45
45
|
urls: o.Array(o.String)
|
|
46
46
|
}),
|
|
47
|
+
publisher: o.optional(o.Struct({
|
|
48
|
+
copyrightHtml: o.String,
|
|
49
|
+
infoHtml: o.String
|
|
50
|
+
})),
|
|
51
|
+
reporting: o.optional(o.Struct({
|
|
52
|
+
kind: o.Literal("api-bible-fums"),
|
|
53
|
+
token: o.NonEmptyString
|
|
54
|
+
})),
|
|
55
|
+
cache: o.optional(o.Struct({ expiresAt: o.Number })),
|
|
47
56
|
licenses: o.Array(o.Struct({
|
|
48
57
|
name: o.optional(o.String),
|
|
49
58
|
url: o.String,
|
|
@@ -157,19 +166,19 @@ function E() {
|
|
|
157
166
|
}
|
|
158
167
|
];
|
|
159
168
|
}
|
|
160
|
-
function D() {
|
|
161
|
-
let
|
|
169
|
+
function D(t = n.infinity) {
|
|
170
|
+
let a = /* @__PURE__ */ new Map(), o = r.runSync(e.makeWith((e) => r.suspend(() => a.get(e)()), {
|
|
162
171
|
capacity: 256,
|
|
163
172
|
requireServicesAt: "lookup",
|
|
164
|
-
timeToLive: (e) => i.isSuccess(e) ?
|
|
173
|
+
timeToLive: (e) => i.isSuccess(e) ? t : n.zero
|
|
165
174
|
}));
|
|
166
175
|
return {
|
|
167
|
-
get(
|
|
168
|
-
return r.suspend(() => (
|
|
169
|
-
|
|
176
|
+
get(t, n) {
|
|
177
|
+
return r.suspend(() => (a.set(t, n), e.get(o, t).pipe(r.ensuring(r.sync(() => {
|
|
178
|
+
a.get(t) === n && a.delete(t);
|
|
170
179
|
})))));
|
|
171
180
|
},
|
|
172
|
-
clear: e.invalidateAll(
|
|
181
|
+
clear: e.invalidateAll(o)
|
|
173
182
|
};
|
|
174
183
|
}
|
|
175
184
|
// src/runtime.ts
|