@nebutra/license 0.1.3 → 2.0.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 CHANGED
@@ -1,5 +1,8 @@
1
1
  # @nebutra/license
2
2
 
3
+ Status: **Foundation** — the issuance and validation contract is usable; the
4
+ database surface is host-injected and delivery needs an email provider.
5
+
3
6
  > License domain logic for issuance, validation, and lifecycle event handling.
4
7
 
5
8
  ## Installation
package/dist/db.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Host-injected system DB surface for license operations.
3
+ * This package never imports private `@nebutra/db`.
4
+ */
5
+ export interface LicenseRecord {
6
+ id: string;
7
+ licenseKey: string;
8
+ userId: string;
9
+ tier: string;
10
+ type: string;
11
+ expiresAt: Date | null;
12
+ }
13
+ export interface LicenseDb {
14
+ license: {
15
+ findFirst(args: {
16
+ where: Record<string, unknown>;
17
+ select?: Record<string, boolean>;
18
+ }): Promise<LicenseRecord | null>;
19
+ create(args: {
20
+ data: Record<string, unknown>;
21
+ }): Promise<LicenseRecord>;
22
+ };
23
+ sleptonsaMemberProfile: {
24
+ findUnique(args: {
25
+ where: {
26
+ user_id: string;
27
+ };
28
+ }): Promise<{
29
+ id: string;
30
+ } | null>;
31
+ create(args: {
32
+ data: Record<string, unknown>;
33
+ }): Promise<{
34
+ id: string;
35
+ member_number: number;
36
+ }>;
37
+ update(args: {
38
+ where: {
39
+ id: string;
40
+ };
41
+ data: Record<string, unknown>;
42
+ }): Promise<unknown>;
43
+ };
44
+ }
45
+ /**
46
+ * Wire host-owned Prisma (e.g. `getSystemDb` from the app data layer).
47
+ */
48
+ export declare function configureLicenseSystemDb(getSystemDb: () => unknown): void;
49
+ /** @internal — tests */
50
+ export declare function __resetLicenseSystemDbForTests(): void;
51
+ export declare function requireLicenseDb(): LicenseDb;
52
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["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;KAC1F,CAAC;CACH;AAID;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,OAAO,GAAG,IAAI,CAEzE;AAED,wBAAwB;AACxB,wBAAgB,8BAA8B,IAAI,IAAI,CAErD;AAED,wBAAgB,gBAAgB,IAAI,SAAS,CAO5C"}
package/dist/db.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Host-injected system DB surface for license operations.
3
+ * This package never imports private `@nebutra/db`.
4
+ */
5
+ let getter;
6
+ /**
7
+ * Wire host-owned Prisma (e.g. `getSystemDb` from the app data layer).
8
+ */
9
+ export function configureLicenseSystemDb(getSystemDb) {
10
+ getter = () => getSystemDb();
11
+ }
12
+ /** @internal — tests */
13
+ export function __resetLicenseSystemDbForTests() {
14
+ getter = undefined;
15
+ }
16
+ export function requireLicenseDb() {
17
+ if (!getter) {
18
+ throw new Error("@nebutra/license requires a host DB client. Call configureLicenseSystemDb(getSystemDb) at app bootstrap.");
19
+ }
20
+ return getter();
21
+ }
@@ -8,6 +8,8 @@ import type { LicenseIssuedEvent } from "../types";
8
8
  *
9
9
  * Designed to be registered with `@nebutra/queue`:
10
10
  * queue.registerHandler("license", "issued", onLicenseIssued)
11
+ *
12
+ * Requires `configureLicenseSystemDb(getSystemDb)` at host bootstrap.
11
13
  */
12
14
  export declare function onLicenseIssued(job: {
13
15
  data: LicenseIssuedEvent;
@@ -1 +1 @@
1
- {"version":3,"file":"on-license-issued.d.ts","sourceRoot":"","sources":["../../src/handlers/on-license-issued.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAInD;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA0DtF"}
1
+ {"version":3,"file":"on-license-issued.d.ts","sourceRoot":"","sources":["../../src/handlers/on-license-issued.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAInD;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA0DtF"}
@@ -1,6 +1,6 @@
1
- import { getSystemDb } from "@nebutra/db";
2
1
  import { sendLicenseCreatedEmail } from "@nebutra/email";
3
2
  import { logger } from "@nebutra/logger";
3
+ import { requireLicenseDb } from "../db";
4
4
  import { generateSlug } from "../generate-slug";
5
5
  const log = logger.child({ service: "license:on-issued" });
6
6
  /**
@@ -12,12 +12,14 @@ const log = logger.child({ service: "license:on-issued" });
12
12
  *
13
13
  * Designed to be registered with `@nebutra/queue`:
14
14
  * queue.registerHandler("license", "issued", onLicenseIssued)
15
+ *
16
+ * Requires `configureLicenseSystemDb(getSystemDb)` at host bootstrap.
15
17
  */
16
18
  export async function onLicenseIssued(job) {
17
19
  const { licenseId, licenseKey, userId, tier, displayName, email, avatarUrl, lookingFor, githubHandle, } = job.data;
18
20
  // AUDIT(no-tenant): Sleptons member profiles are keyed on user_id and
19
21
  // are not per-tenant — they belong to the global community namespace.
20
- const db = getSystemDb();
22
+ const db = requireLicenseDb();
21
23
  // 1. Create Sleptons member profile
22
24
  const existingProfile = await db.sleptonsaMemberProfile.findUnique({
23
25
  where: { user_id: userId },
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { configureLicenseSystemDb, type LicenseDb, type LicenseRecord, } from "./db";
1
2
  export { generateSlug } from "./generate-slug";
2
3
  export { issueLicense } from "./issue-license";
3
4
  export type { IssueLicenseParams, IssueLicenseResult, LicenseIssuedEvent, LicenseTier, LicenseType, ValidateLicenseResult, } from "./types";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,qBAAqB,GACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,SAAS,EACd,KAAK,aAAa,GACnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,qBAAqB,GACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { configureLicenseSystemDb, } from "./db";
1
2
  export { generateSlug } from "./generate-slug";
2
3
  export { issueLicense } from "./issue-license";
3
4
  export { LicenseTierSchema, LicenseTypeSchema } from "./types";
@@ -7,6 +7,8 @@ import type { IssueLicenseParams, IssueLicenseResult } from "./types";
7
7
  * - Enqueues a `license.issued` event for downstream handlers
8
8
  * (member profile creation, welcome email, etc.)
9
9
  * - Idempotent: returns existing license if user+tier already exists
10
+ *
11
+ * Requires `configureLicenseSystemDb(getSystemDb)` at host bootstrap.
10
12
  */
11
13
  export declare function issueLicense(params: IssueLicenseParams): Promise<IssueLicenseResult>;
12
14
  //# sourceMappingURL=issue-license.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"issue-license.d.ts","sourceRoot":"","sources":["../src/issue-license.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAUjB;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkE1F"}
1
+ {"version":3,"file":"issue-license.d.ts","sourceRoot":"","sources":["../src/issue-license.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAUjB;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkE1F"}
@@ -1,6 +1,6 @@
1
- import { getSystemDb } from "@nebutra/db";
2
1
  import { logger } from "@nebutra/logger";
3
2
  import { createJob, getQueue } from "@nebutra/queue";
3
+ import { requireLicenseDb } from "./db";
4
4
  const log = logger.child({ service: "license" });
5
5
  const ONE_YEAR_MS = 365 * 24 * 60 * 60 * 1000;
6
6
  function resolveLicenseType(tier) {
@@ -14,12 +14,14 @@ function resolveLicenseType(tier) {
14
14
  * - Enqueues a `license.issued` event for downstream handlers
15
15
  * (member profile creation, welcome email, etc.)
16
16
  * - Idempotent: returns existing license if user+tier already exists
17
+ *
18
+ * Requires `configureLicenseSystemDb(getSystemDb)` at host bootstrap.
17
19
  */
18
20
  export async function issueLicense(params) {
19
21
  const { userId, tier } = params;
20
22
  // AUDIT(no-tenant): licenses are user-scoped (not tenant-scoped); they pre-
21
23
  // date any Organization membership and are queried by userId/licenseKey.
22
- const db = getSystemDb();
24
+ const db = requireLicenseDb();
23
25
  // Idempotency: check for existing license
24
26
  const existing = await db.license.findFirst({
25
27
  where: { userId, tier },
@@ -6,6 +6,8 @@ import type { ValidateLicenseResult } from "./types";
6
6
  * Used by the CLI `nebutra license activate` and the public
7
7
  * `/api/license/validate` endpoint.
8
8
  *
9
+ * Requires `configureLicenseSystemDb(getSystemDb)` at host bootstrap.
10
+ *
9
11
  * AUDIT(no-tenant): licenses are keyed on userId and are not scoped to any
10
12
  * Organization; the validate flow runs pre-auth against a global key space.
11
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"validate-license.d.ts","sourceRoot":"","sources":["../src/validate-license.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAoBjF"}
1
+ {"version":3,"file":"validate-license.d.ts","sourceRoot":"","sources":["../src/validate-license.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAoBjF"}
@@ -1,4 +1,4 @@
1
- import { getSystemDb } from "@nebutra/db";
1
+ import { requireLicenseDb } from "./db";
2
2
  /**
3
3
  * Validate a license key.
4
4
  *
@@ -6,11 +6,13 @@ import { getSystemDb } from "@nebutra/db";
6
6
  * Used by the CLI `nebutra license activate` and the public
7
7
  * `/api/license/validate` endpoint.
8
8
  *
9
+ * Requires `configureLicenseSystemDb(getSystemDb)` at host bootstrap.
10
+ *
9
11
  * AUDIT(no-tenant): licenses are keyed on userId and are not scoped to any
10
12
  * Organization; the validate flow runs pre-auth against a global key space.
11
13
  */
12
14
  export async function validateLicense(key) {
13
- const license = await getSystemDb().license.findFirst({
15
+ const license = await requireLicenseDb().license.findFirst({
14
16
  where: { licenseKey: key, isActive: true },
15
17
  select: { tier: true, type: true, expiresAt: true },
16
18
  });
package/package.json CHANGED
@@ -1,14 +1,27 @@
1
1
  {
2
2
  "name": "@nebutra/license",
3
- "version": "0.1.3",
3
+ "version": "2.0.0",
4
4
  "description": "License domain logic — issuance, validation, and lifecycle events",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "nebutra": {
9
+ "graph": "core",
9
10
  "featureId": "license",
10
11
  "category": "commerce",
11
- "summary": "License key generation + validation"
12
+ "summary": "License key generation + validation",
13
+ "status": "foundation",
14
+ "productionReady": false,
15
+ "requires": [
16
+ "Host-injected getSystemDb via configureLicenseSystemDb",
17
+ "@nebutra/queue for license.issued fan-out",
18
+ "@nebutra/email for welcome mail (handler)"
19
+ ],
20
+ "gaps": [
21
+ "Persistence is host-injected — the package defines a LicenseDb interface and deliberately never imports @nebutra/db",
22
+ "Issuance sends through @nebutra/email, so a working email provider must be configured before a key reaches anyone",
23
+ "No UI surface: key entry, activation and portal screens belong to the consuming app"
24
+ ]
12
25
  },
13
26
  "main": "./dist/index.js",
14
27
  "types": "./dist/index.d.ts",
@@ -28,23 +41,14 @@
28
41
  ],
29
42
  "dependencies": {
30
43
  "zod": "^4.3.6",
31
- "@nebutra/email": "0.1.2",
32
- "@nebutra/logger": "0.1.2",
33
- "@nebutra/queue": "0.1.3"
34
- },
35
- "peerDependencies": {
36
- "@nebutra/db": "0.1.2"
37
- },
38
- "peerDependenciesMeta": {
39
- "@nebutra/db": {
40
- "optional": true
41
- }
44
+ "@nebutra/email": "2.0.0",
45
+ "@nebutra/logger": "2.0.0",
46
+ "@nebutra/queue": "2.0.0"
42
47
  },
43
48
  "devDependencies": {
44
49
  "@vitest/coverage-v8": "^4.1.4",
45
50
  "typescript": "^5.9.3",
46
- "vitest": "^4.1.4",
47
- "@nebutra/db": "0.1.2"
51
+ "vitest": "^4.1.4"
48
52
  },
49
53
  "homepage": "https://github.com/Nebutra/Nebutra-Sailor/tree/main/packages/commerce/license#readme",
50
54
  "repository": {