@nebutra/license 0.1.2 → 0.1.4
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 +21 -0
- package/dist/db.d.ts +52 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +21 -0
- package/dist/handlers/on-license-issued.d.ts +2 -0
- package/dist/handlers/on-license-issued.d.ts.map +1 -1
- package/dist/handlers/on-license-issued.js +4 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/issue-license.d.ts +2 -0
- package/dist/issue-license.d.ts.map +1 -1
- package/dist/issue-license.js +4 -2
- package/dist/validate-license.d.ts +2 -0
- package/dist/validate-license.d.ts.map +1 -1
- package/dist/validate-license.js +4 -2
- package/package.json +13 -15
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wuxi Nebutra Intelligence Technology Co., Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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
|
package/dist/db.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE;QACP,SAAS,CAAC,IAAI,EAAE;YACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SAClC,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;QAClC,MAAM,CAAC,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;KACzE,CAAC;IACF,sBAAsB,EAAE;QACtB,UAAU,CAAC,IAAI,EAAE;YAAE,KAAK,EAAE;gBAAE,OAAO,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,GAAG,OAAO,CAAC;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,GAAG,IAAI,CAAC,CAAC;QACjF,MAAM,CAAC,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,GAAG,OAAO,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,aAAa,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAChG,MAAM,CAAC,IAAI,EAAE;YAAE,KAAK,EAAE;gBAAE,EAAE,EAAE,MAAM,CAAA;aAAE,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;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
|
|
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 =
|
|
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";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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
package/dist/issue-license.d.ts
CHANGED
|
@@ -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
|
|
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"}
|
package/dist/issue-license.js
CHANGED
|
@@ -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 =
|
|
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
|
|
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"}
|
package/dist/validate-license.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nebutra/license",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "License domain logic — issuance, validation, and lifecycle events",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,14 @@
|
|
|
8
8
|
"nebutra": {
|
|
9
9
|
"featureId": "license",
|
|
10
10
|
"category": "commerce",
|
|
11
|
-
"summary": "License key generation + validation"
|
|
11
|
+
"summary": "License key generation + validation",
|
|
12
|
+
"status": "foundation",
|
|
13
|
+
"productionReady": false,
|
|
14
|
+
"requires": [
|
|
15
|
+
"Host-injected getSystemDb via configureLicenseSystemDb",
|
|
16
|
+
"@nebutra/queue for license.issued fan-out",
|
|
17
|
+
"@nebutra/email for welcome mail (handler)"
|
|
18
|
+
]
|
|
12
19
|
},
|
|
13
20
|
"main": "./dist/index.js",
|
|
14
21
|
"types": "./dist/index.d.ts",
|
|
@@ -28,23 +35,14 @@
|
|
|
28
35
|
],
|
|
29
36
|
"dependencies": {
|
|
30
37
|
"zod": "^4.3.6",
|
|
31
|
-
"@nebutra/
|
|
32
|
-
"@nebutra/
|
|
33
|
-
"@nebutra/
|
|
34
|
-
},
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"@nebutra/db": "0.1.1"
|
|
37
|
-
},
|
|
38
|
-
"peerDependenciesMeta": {
|
|
39
|
-
"@nebutra/db": {
|
|
40
|
-
"optional": true
|
|
41
|
-
}
|
|
38
|
+
"@nebutra/queue": "0.1.4",
|
|
39
|
+
"@nebutra/email": "0.1.2",
|
|
40
|
+
"@nebutra/logger": "0.1.2"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@vitest/coverage-v8": "^4.1.4",
|
|
45
44
|
"typescript": "^5.9.3",
|
|
46
|
-
"vitest": "^4.1.4"
|
|
47
|
-
"@nebutra/db": "0.1.1"
|
|
45
|
+
"vitest": "^4.1.4"
|
|
48
46
|
},
|
|
49
47
|
"homepage": "https://github.com/Nebutra/Nebutra-Sailor/tree/main/packages/commerce/license#readme",
|
|
50
48
|
"repository": {
|