@happyvertical/smrt-cli 0.51.14 → 0.51.16
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/AGENTS.md +1 -0
- package/dist/ApiKey-BZmbOTnL-Dz-PO2sa.js +157 -0
- package/dist/ApiKeyCollection-Bfb_nw81-Dks_0546.js +2 -0
- package/dist/AuditLogCollection-B1YonCAP-Db9tLDtf.js +2 -0
- package/dist/NostrIdentity-n70E0vck-CZwoR7Rs.js +4189 -0
- package/dist/NostrIdentityCollection-Ca74dkaL-DESXyrjY.js +2 -0
- package/dist/OidcIdentity-CChQnYNH-DV9jiJ5r.js +117 -0
- package/dist/OidcIdentityCollection-D3L0WYbM-C85jz9CB.js +2 -0
- package/dist/ProfileAssetCollection-V8u4wqSL-BKz6v8py.js +2 -0
- package/dist/ProfileCollection-BvhD2cfL-CT6ctQ3l.js +1753 -0
- package/dist/ProfileMetadataCollection-DxX_BJKV-StatXt-E.js +2 -0
- package/dist/ProfileMetafieldCollection-CMKhVi2I--ba-T4qA.js +2 -0
- package/dist/ProfileRelationshipCollection-DUVgaIqf-B4TDc4TQ.js +2 -0
- package/dist/ProfileRelationshipTermCollection-DtA9OM23-1ZkGUm00.js +2 -0
- package/dist/ProfileRelationshipType-BRiRka6t-Dw1efEX5.js +101 -0
- package/dist/ProfileRelationshipTypeCollection-BdXwd7Kf-GEu0alx6.js +2 -0
- package/dist/{commands-BhDS-TVS.js → commands-CL85adn5.js} +95 -21
- package/dist/{config-DfBo4hHU.js → config-hqNo4lzH.js} +1 -13
- package/dist/dist-9EA_5mOX.js +142 -0
- package/dist/dist-BIA7A6wF.js +3712 -0
- package/dist/dist-mLcl4Ttr.js +1487 -0
- package/dist/index.js +14 -14
- package/dist/{json-validator-CjX8fHx9.js → json-validator-oEN7eUI3.js} +1 -1
- package/dist/oidcProvisioningPrimitives-CjOkg3Zd-DhC5lyKE.js +161 -0
- package/dist/resolveIdentity-73HQnTlT-DQB4z5h5.js +2 -0
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/package.json +8 -7
package/AGENTS.md
CHANGED
|
@@ -18,6 +18,7 @@ smrt db:migrate --apply-unblocked / --null-orphans # agents/db-migrate-partial-a
|
|
|
18
18
|
smrt db:migrate-uuid # Convert schema-declared UUID text columns after data remap
|
|
19
19
|
smrt db:migrate-int8
|
|
20
20
|
smrt db:migrate-null-equal-indexes # ../core/agents/null-equal-indexes.md
|
|
21
|
+
smrt db:materialize-tenant-hierarchy [--dry-run] # smrt-users tenant hierarchy_path backfill (#3036)
|
|
21
22
|
smrt db:drop-framework-base-tables # One-time drop of the five #2644-orphaned framework-base tables
|
|
22
23
|
smrt db:drop-framework-base-tables --dry-run # Print the drop plan without executing
|
|
23
24
|
smrt db:diff # Show schema differences without generating migration files
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
+
import { n as __exportAll$1 } from "./NostrIdentity-n70E0vck-CZwoR7Rs.js";
|
|
3
|
+
import { SmrtObject, field, foreignKey, smrt } from "@happyvertical/smrt-core";
|
|
4
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
5
|
+
//#region ../profiles/dist/chunks/ApiKey-BZmbOTnL.js
|
|
6
|
+
var ApiKey_BZmbOTnL_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
n: () => ApiKey_exports,
|
|
8
|
+
t: () => ApiKey
|
|
9
|
+
});
|
|
10
|
+
var ApiKey_exports = /* @__PURE__ */ __exportAll$1({ ApiKey: () => ApiKey });
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
14
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
15
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
16
|
+
if (kind && result) __defProp(target, key, result);
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
var ApiKey = class extends SmrtObject {
|
|
20
|
+
profileId;
|
|
21
|
+
keyHash = "";
|
|
22
|
+
/**
|
|
23
|
+
* First 8 characters of the key for identification (e.g., "sk_live_a1b2...")
|
|
24
|
+
*/
|
|
25
|
+
keyPrefix = "";
|
|
26
|
+
/**
|
|
27
|
+
* Human-readable name for the key (e.g., "CI Bot", "Local CLI")
|
|
28
|
+
*/
|
|
29
|
+
name = "";
|
|
30
|
+
/**
|
|
31
|
+
* Scopes/permissions for this key
|
|
32
|
+
*/
|
|
33
|
+
scopes = [];
|
|
34
|
+
/**
|
|
35
|
+
* Last time this key was used
|
|
36
|
+
*/
|
|
37
|
+
lastUsedAt = null;
|
|
38
|
+
/**
|
|
39
|
+
* When this key expires (null = never)
|
|
40
|
+
*/
|
|
41
|
+
expiresAt = null;
|
|
42
|
+
/**
|
|
43
|
+
* When this key was revoked (null = active)
|
|
44
|
+
*/
|
|
45
|
+
revokedAt = null;
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
super(options);
|
|
48
|
+
if (options.profileId) this.profileId = options.profileId;
|
|
49
|
+
if (options.name) this.name = options.name;
|
|
50
|
+
if (options.scopes) this.scopes = options.scopes;
|
|
51
|
+
if (options.expiresAt !== void 0) this.expiresAt = options.expiresAt;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the linked Profile
|
|
55
|
+
*/
|
|
56
|
+
async getProfile() {
|
|
57
|
+
return await this.getRelated("profileId");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if this key is valid (not expired, not revoked)
|
|
61
|
+
*/
|
|
62
|
+
isValid() {
|
|
63
|
+
if (this.revokedAt) return false;
|
|
64
|
+
if (this.expiresAt && this.expiresAt < /* @__PURE__ */ new Date()) return false;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if this key has a specific scope
|
|
69
|
+
*/
|
|
70
|
+
hasScope(scope) {
|
|
71
|
+
return this.scopes.includes(scope) || this.scopes.includes("*");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Revoke this key
|
|
75
|
+
*/
|
|
76
|
+
async revoke() {
|
|
77
|
+
this.revokedAt = /* @__PURE__ */ new Date();
|
|
78
|
+
await this.save();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Record usage of this key
|
|
82
|
+
*/
|
|
83
|
+
async recordUsage() {
|
|
84
|
+
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
85
|
+
if (this.isPersisted) await this.loadFromId();
|
|
86
|
+
if (!this.isValid()) return;
|
|
87
|
+
this.lastUsedAt = /* @__PURE__ */ new Date();
|
|
88
|
+
try {
|
|
89
|
+
await this.save();
|
|
90
|
+
return;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (attempt === 3 || !(error instanceof Error && "code" in error && error.code === "RUNTIME_REVISION_CONFLICT")) throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Hash an API key
|
|
98
|
+
*/
|
|
99
|
+
static hashKey(key) {
|
|
100
|
+
return createHash("sha256").update(key).digest("hex");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Generate a new API key for a profile
|
|
104
|
+
*/
|
|
105
|
+
static async generate(profile, options) {
|
|
106
|
+
const key = `sk_live_${randomBytes(32).toString("hex")}`;
|
|
107
|
+
const keyPrefix = key.substring(0, 16);
|
|
108
|
+
const keyHash = ApiKey.hashKey(key);
|
|
109
|
+
const apiKey = new ApiKey({
|
|
110
|
+
db: options.db || profile.options?.db,
|
|
111
|
+
profileId: profile.id,
|
|
112
|
+
name: options.name,
|
|
113
|
+
scopes: options.scopes || ["*"],
|
|
114
|
+
expiresAt: options.expiresAt ?? null
|
|
115
|
+
});
|
|
116
|
+
apiKey.keyHash = keyHash;
|
|
117
|
+
apiKey.keyPrefix = keyPrefix;
|
|
118
|
+
await apiKey.initialize();
|
|
119
|
+
await apiKey.save();
|
|
120
|
+
return {
|
|
121
|
+
key,
|
|
122
|
+
apiKey
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Verify an API key and return the ApiKey record if valid
|
|
127
|
+
*/
|
|
128
|
+
static async verify(key, options = {}) {
|
|
129
|
+
const keyHash = ApiKey.hashKey(key);
|
|
130
|
+
const { ApiKeyCollection } = await import("./ApiKeyCollection-Bfb_nw81-Dks_0546.js").then((n) => n.n);
|
|
131
|
+
const apiKey = await (await ApiKeyCollection.create(options)).findOne({ where: { keyHash } });
|
|
132
|
+
if (!apiKey) return null;
|
|
133
|
+
if (!apiKey.isValid()) return null;
|
|
134
|
+
await apiKey.recordUsage();
|
|
135
|
+
if (!apiKey.isValid()) return null;
|
|
136
|
+
return apiKey;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
__decorateClass([foreignKey("Profile", { required: true })], ApiKey.prototype, "profileId", 2);
|
|
140
|
+
__decorateClass([field({ indexed: true })], ApiKey.prototype, "keyHash", 2);
|
|
141
|
+
ApiKey = __decorateClass([smrt({
|
|
142
|
+
tableName: "api_keys",
|
|
143
|
+
sensitive: true,
|
|
144
|
+
api: { include: ["list", "get"] },
|
|
145
|
+
mcp: { include: ["list", "get"] },
|
|
146
|
+
cli: {
|
|
147
|
+
include: [
|
|
148
|
+
"list",
|
|
149
|
+
"get",
|
|
150
|
+
"create",
|
|
151
|
+
"revoke"
|
|
152
|
+
],
|
|
153
|
+
skipApiCheck: true
|
|
154
|
+
}
|
|
155
|
+
})], ApiKey);
|
|
156
|
+
//#endregion
|
|
157
|
+
export { ApiKey_BZmbOTnL_exports as n, ApiKey as t };
|