@voltro/plugin-licensing 0.33.0 → 0.35.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 (3) hide show
  1. package/CHANGELOG.md +1968 -0
  2. package/dist/index.js +47 -44
  3. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,58 +1,58 @@
1
1
  import { Data as e, Effect as t } from "effect";
2
- import { definePlugin as n, definePluginService as r } from "@voltro/protocol";
3
- import { pluginEnv as i } from "@voltro/env";
4
- import { importSPKI as a, jwtVerify as o } from "jose";
2
+ import { definePlugin as n, definePluginService as r, pluginInstanceName as i } from "@voltro/protocol";
3
+ import { pluginEnv as a } from "@voltro/env";
4
+ import { importSPKI as o, jwtVerify as s } from "jose";
5
5
  //#region src/verify.ts
6
- var s = class extends e.TaggedError("LicenseVerifyError") {}, c = (e) => typeof e == "object" && e && "code" in e ? String(e.code) : "", l = (e) => {
6
+ var c = class extends e.TaggedError("LicenseVerifyError") {}, l = (e) => typeof e == "object" && e && "code" in e ? String(e.code) : "", u = (e) => {
7
7
  let t = e instanceof Error ? e.message : String(e);
8
- return c(e) === "ERR_JWT_EXPIRED" ? new s({
8
+ return l(e) === "ERR_JWT_EXPIRED" ? new c({
9
9
  reason: "expired",
10
10
  message: t
11
- }) : new s({
11
+ }) : new c({
12
12
  reason: "invalid",
13
13
  message: t
14
14
  });
15
- }, u = (e) => e === "unlimited" || typeof e == "number" && Number.isFinite(e) && e >= 0, d = (e, n) => {
15
+ }, d = (e) => e === "unlimited" || typeof e == "number" && Number.isFinite(e) && e >= 0, f = (e, n) => {
16
16
  let r = e.edition, i = e.entitlements, a = e.features;
17
- if (typeof r != "string" || typeof i != "object" || !i) return t.fail(new s({
17
+ if (typeof r != "string" || typeof i != "object" || !i) return t.fail(new c({
18
18
  reason: "malformed",
19
19
  message: "missing edition/entitlements"
20
20
  }));
21
21
  let o = {};
22
22
  for (let [e, n] of Object.entries(i)) {
23
- if (!u(n)) return t.fail(new s({
23
+ if (!d(n)) return t.fail(new c({
24
24
  reason: "malformed",
25
25
  message: `bad entitlement '${e}'`
26
26
  }));
27
27
  o[e] = n;
28
28
  }
29
- let c = Array.isArray(a) ? a.filter((e) => typeof e == "string") : [], l = e.plugins, d = Array.isArray(l) ? l.filter((e) => typeof e == "string") : [];
29
+ let s = Array.isArray(a) ? a.filter((e) => typeof e == "string") : [], l = e.plugins, u = Array.isArray(l) ? l.filter((e) => typeof e == "string") : [];
30
30
  return t.succeed({
31
31
  ...typeof e.tenant == "string" ? { tenant: e.tenant } : {},
32
32
  edition: r,
33
33
  entitlements: o,
34
- features: c,
35
- plugins: d,
34
+ features: s,
35
+ plugins: u,
36
36
  exp: typeof e.exp == "number" ? e.exp : 0,
37
37
  ...typeof e.iat == "number" ? { iat: e.iat } : {},
38
38
  ...n === void 0 ? {} : { kid: n }
39
39
  });
40
- }, f = (e, n) => t.tryPromise({
41
- try: () => a(n, "EdDSA"),
42
- catch: (e) => new s({
40
+ }, p = (e, n) => t.tryPromise({
41
+ try: () => o(n, "EdDSA"),
42
+ catch: (e) => new c({
43
43
  reason: "key",
44
44
  message: e instanceof Error ? e.message : String(e)
45
45
  })
46
46
  }).pipe(t.flatMap((n) => t.tryPromise({
47
47
  try: async () => {
48
- let { payload: t, protectedHeader: r } = await o(e, n, { algorithms: ["EdDSA"] });
48
+ let { payload: t, protectedHeader: r } = await s(e, n, { algorithms: ["EdDSA"] });
49
49
  return {
50
50
  payload: t,
51
51
  kid: r.kid
52
52
  };
53
53
  },
54
- catch: l
55
- })), t.flatMap(({ payload: e, kid: t }) => d(e, t))), p = (e, t = {}) => {
54
+ catch: u
55
+ })), t.flatMap(({ payload: e, kid: t }) => f(e, t))), m = (e, t = {}) => {
56
56
  let n = new Set(e.features), r = new Set(e.plugins), i = t.graceSeconds ?? 0, a = t.now ?? (() => Date.now() / 1e3), o = () => e.exp <= 0 || a() <= e.exp + i;
57
57
  return {
58
58
  claims: e,
@@ -64,12 +64,12 @@ var s = class extends e.TaggedError("LicenseVerifyError") {}, c = (e) => typeof
64
64
  hasFeature: (e) => o() && n.has(e),
65
65
  allowsPlugin: (e) => o() && r.has(e)
66
66
  };
67
- }, m, h = (e) => {
68
- m = e;
69
- }, g = () => m, _ = (e, n) => t.sync(() => {
70
- let t = g()?.limitFor(e, n);
67
+ }, h, g = (e) => {
68
+ h = e;
69
+ }, _ = () => h, v = (e, n) => t.sync(() => {
70
+ let t = _()?.limitFor(e, n);
71
71
  return t === void 0 ? null : t;
72
- }), v = i([{
72
+ }), y = a([{
73
73
  name: "VOLTRO_LICENSE_PUBLIC_KEY",
74
74
  required: !1,
75
75
  secret: !1,
@@ -79,57 +79,60 @@ var s = class extends e.TaggedError("LicenseVerifyError") {}, c = (e) => typeof
79
79
  required: !1,
80
80
  secret: !1,
81
81
  description: "The signed EdDSA license token, verified offline at boot."
82
- }]), { Tag: y, Live: b } = r("@voltro/plugin-licensing/LicenseService", {
83
- snapshot: () => g(),
84
- limitFor: (e, t) => g()?.limitFor(e, t),
85
- hasFeature: (e) => g()?.hasFeature(e) ?? !1,
86
- allowsPlugin: (e) => g()?.allowsPlugin(e) ?? !1,
87
- edition: () => g()?.claims.edition
88
- }), x = class extends e.TaggedError("PluginNotLicensed") {}, S = (e) => g()?.allowsPlugin(e) ?? !1, C = (e) => S(e) ? t.void : t.fail(new x({ plugin: e })), w = (e = {}) => {
89
- let r = v.read("VOLTRO_LICENSE_PUBLIC_KEY", e.publicKey), i = v.read("VOLTRO_LICENSE_KEY", e.licenseKey), a = e.graceSeconds ?? 0, o = e.refreshMs ?? 15 * 6e4, s, c = (e, n) => f(e, n).pipe(t.match({
82
+ }]), { Tag: b, Live: x } = r("@voltro/plugin-licensing/LicenseService", {
83
+ snapshot: () => _(),
84
+ limitFor: (e, t) => _()?.limitFor(e, t),
85
+ hasFeature: (e) => _()?.hasFeature(e) ?? !1,
86
+ allowsPlugin: (e) => _()?.allowsPlugin(e) ?? !1,
87
+ edition: () => _()?.claims.edition
88
+ }), S = class extends e.TaggedError("PluginNotLicensed") {}, C = (e) => _()?.allowsPlugin(e) ?? !1, w = (e) => C(e) ? t.void : t.fail(new S({ plugin: e })), T = (e = {}) => {
89
+ let r = y.read("VOLTRO_LICENSE_PUBLIC_KEY", e.publicKey), a = y.read("VOLTRO_LICENSE_KEY", e.licenseKey), o = e.graceSeconds ?? 0, s = e.refreshMs ?? 15 * 6e4, c, l = (e, n) => p(e, n).pipe(t.match({
90
90
  onSuccess: (e) => {
91
- h(p(e, { graceSeconds: a })), s?.info("license active", {
91
+ g(m(e, { graceSeconds: o })), c?.info("license active", {
92
92
  edition: e.edition,
93
93
  entitlements: Object.keys(e.entitlements).length,
94
94
  exp: e.exp
95
95
  });
96
96
  },
97
97
  onFailure: (e) => {
98
- s?.warn("license verification failed — entitlements fall back to static plan", {
98
+ c?.warn("license verification failed — entitlements fall back to static plan", {
99
99
  reason: e.reason,
100
100
  message: e.message
101
101
  });
102
102
  }
103
103
  }));
104
104
  return n({
105
- name: e.name ? `@voltro/plugin-licensing#${e.name}` : "@voltro/plugin-licensing",
105
+ name: i({
106
+ base: "@voltro/plugin-licensing",
107
+ instance: e.name
108
+ }),
106
109
  description: "Offline-verified EdDSA license keys + entitlement snapshots; feeds @voltro/plugin-billing via entitlementResolver.",
107
- declaredEnv: v.declared,
108
- services: b,
110
+ declaredEnv: y.declared,
111
+ services: x,
109
112
  onActivate: (e) => t.gen(function* () {
110
- if (s = e.logger, r === void 0 || i === void 0) {
113
+ if (c = e.logger, r === void 0 || a === void 0) {
111
114
  e.logger.debug("licensing: no license configured — static plan entitlements apply");
112
115
  return;
113
116
  }
114
- yield* c(i, r);
117
+ yield* l(a, r);
115
118
  }),
116
119
  bindDataStore: (n, i) => {
117
120
  let a = e.snapshotUrl;
118
121
  if (a === void 0 || r === void 0 || i?.scheduleCoordinated === void 0) return;
119
- let l = r;
120
- i.scheduleCoordinated("licensing.refresh", o, async () => {
122
+ let o = r;
123
+ i.scheduleCoordinated("licensing.refresh", s, async () => {
121
124
  try {
122
125
  let e = await fetch(a);
123
126
  if (!e.ok) return;
124
127
  let n = (await e.text()).trim();
125
- n.length > 0 && await t.runPromise(c(n, l));
128
+ n.length > 0 && await t.runPromise(l(n, o));
126
129
  } catch (e) {
127
- s?.warn("license refresh failed", { message: e instanceof Error ? e.message : String(e) });
130
+ c?.warn("license refresh failed", { message: e instanceof Error ? e.message : String(e) });
128
131
  }
129
132
  });
130
133
  },
131
- onDeactivate: () => t.sync(() => h(void 0))
134
+ onDeactivate: () => t.sync(() => g(void 0))
132
135
  });
133
136
  };
134
137
  //#endregion
135
- export { y as LicenseService, s as LicenseVerifyError, x as PluginNotLicensed, _ as entitlementResolver, S as licenseAllowsPlugin, w as licensingPlugin, C as requireLicensedPlugin, f as verifyLicense };
138
+ export { b as LicenseService, c as LicenseVerifyError, S as PluginNotLicensed, v as entitlementResolver, C as licenseAllowsPlugin, T as licensingPlugin, w as requireLicensedPlugin, p as verifyLicense };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/plugin-licensing",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "Offline-verified license keys + cloud-issued entitlement snapshots for @voltro apps",
5
5
  "keywords": [
6
6
  "voltro",
@@ -38,10 +38,10 @@
38
38
  "node": ">=24.0.0"
39
39
  },
40
40
  "dependencies": {
41
- "@voltro/database": "0.33.0",
42
- "@voltro/env": "0.33.0",
43
- "@voltro/logger": "0.33.0",
44
- "@voltro/protocol": "0.33.0",
41
+ "@voltro/database": "0.35.0",
42
+ "@voltro/env": "0.35.0",
43
+ "@voltro/logger": "0.35.0",
44
+ "@voltro/protocol": "0.35.0",
45
45
  "jose": "^6.2.4"
46
46
  },
47
47
  "peerDependencies": {