@marichi-labs-tech/rbac-sdk 0.0.0-stage → 0.2.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/dist/index.d.ts +261 -0
- package/dist/index.js +541 -0
- package/package.json +31 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { ParamValue, CheckResult, Grant, DenyReason, ParamDef } from '@marichi-labs-tech/rbac-manifest-schema';
|
|
2
|
+
export { CheckResult, DenyReason, Grant, ParamValue } from '@marichi-labs-tech/rbac-manifest-schema';
|
|
3
|
+
|
|
4
|
+
interface Subject {
|
|
5
|
+
orgId: string;
|
|
6
|
+
roleIds: string[];
|
|
7
|
+
}
|
|
8
|
+
interface RbacClientOptions {
|
|
9
|
+
url: string;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/** Must equal the product ID from the admin panel. */
|
|
12
|
+
product: string;
|
|
13
|
+
/** How long an expired cache entry may be served while RBAC is unreachable. Default 5 minutes. */
|
|
14
|
+
maxStaleMs?: number;
|
|
15
|
+
/** Per-request timeout for calls to RBAC. A timeout counts as unreachable (stale or 503). Default 5 s. */
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
now?: () => number;
|
|
19
|
+
logger?: {
|
|
20
|
+
warn(...args: unknown[]): void;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
interface ClientStats {
|
|
24
|
+
checks: number;
|
|
25
|
+
allowed: number;
|
|
26
|
+
denied: number;
|
|
27
|
+
cacheHits: number;
|
|
28
|
+
cacheMisses: number;
|
|
29
|
+
staleServed: number;
|
|
30
|
+
}
|
|
31
|
+
interface PermissionView {
|
|
32
|
+
key: string;
|
|
33
|
+
scope: string | null;
|
|
34
|
+
params: Record<string, ParamValue>;
|
|
35
|
+
}
|
|
36
|
+
/** The check surface shared by RbacClient and createMockRbac. */
|
|
37
|
+
interface RbacChecker {
|
|
38
|
+
resolve(subject: Subject, perm: string): Promise<CheckResult>;
|
|
39
|
+
can(subject: Subject, perm: string): Promise<boolean>;
|
|
40
|
+
assert(subject: Subject, perm: string): Promise<void>;
|
|
41
|
+
scope(subject: Subject, perm: string): Promise<string | null>;
|
|
42
|
+
param(subject: Subject, perm: string, name: string): Promise<ParamValue | null>;
|
|
43
|
+
permissions(subject: Subject): Promise<PermissionView[]>;
|
|
44
|
+
}
|
|
45
|
+
interface RoleView {
|
|
46
|
+
id: string;
|
|
47
|
+
orgId: string;
|
|
48
|
+
key: string;
|
|
49
|
+
name: string;
|
|
50
|
+
description: string;
|
|
51
|
+
source: "template" | "custom";
|
|
52
|
+
templateKey: string | null;
|
|
53
|
+
customized: boolean;
|
|
54
|
+
grants: Grant[];
|
|
55
|
+
}
|
|
56
|
+
/** A change RBAC reported on the invalidation stream: one org's roles, or everything. */
|
|
57
|
+
type InvalidationEvent = {
|
|
58
|
+
type: "org";
|
|
59
|
+
orgId: string;
|
|
60
|
+
} | {
|
|
61
|
+
type: "all";
|
|
62
|
+
};
|
|
63
|
+
interface SubscribeOptions {
|
|
64
|
+
/**
|
|
65
|
+
* Called after the SDK cache is cleared for each org or all event. Not awaited, so handlers may overlap;
|
|
66
|
+
* a throw or rejection is logged and the stream carries on. Events missed while disconnected are not replayed.
|
|
67
|
+
*/
|
|
68
|
+
onEvent?: (event: InvalidationEvent) => void | Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
type GrantInput = string | {
|
|
71
|
+
permission: string;
|
|
72
|
+
scope?: string | null;
|
|
73
|
+
params?: Record<string, ParamValue>;
|
|
74
|
+
};
|
|
75
|
+
declare class RbacClient implements RbacChecker {
|
|
76
|
+
private readonly opts;
|
|
77
|
+
private readonly cache;
|
|
78
|
+
private readonly counters;
|
|
79
|
+
private readonly inflight;
|
|
80
|
+
private readonly baseUrl;
|
|
81
|
+
private readonly maxStaleMs;
|
|
82
|
+
private readonly timeoutMs;
|
|
83
|
+
private readonly doFetch;
|
|
84
|
+
private readonly now;
|
|
85
|
+
private streamOn;
|
|
86
|
+
private streamAbort?;
|
|
87
|
+
private streamRetry?;
|
|
88
|
+
private streamWatchdog?;
|
|
89
|
+
private streamAttempt;
|
|
90
|
+
private onEvent?;
|
|
91
|
+
constructor(opts: RbacClientOptions);
|
|
92
|
+
/** Counters since construction, for the product's own metrics. */
|
|
93
|
+
stats(): ClientStats;
|
|
94
|
+
resolve(subject: Subject, perm: string): Promise<CheckResult>;
|
|
95
|
+
private decide;
|
|
96
|
+
can(subject: Subject, perm: string): Promise<boolean>;
|
|
97
|
+
assert(subject: Subject, perm: string): Promise<void>;
|
|
98
|
+
scope(subject: Subject, perm: string): Promise<string | null>;
|
|
99
|
+
param(subject: Subject, perm: string, name: string): Promise<ParamValue | null>;
|
|
100
|
+
/** Everything the subject may do in this product, for the frontend. */
|
|
101
|
+
permissions(subject: Subject): Promise<PermissionView[]>;
|
|
102
|
+
ensureOrg(orgId: string, name: string): Promise<{
|
|
103
|
+
org: unknown;
|
|
104
|
+
adminRoleId: string;
|
|
105
|
+
roles: RoleView[];
|
|
106
|
+
}>;
|
|
107
|
+
canAssign(orgId: string, actorRoleIds: string[], roleIds: string[]): Promise<boolean>;
|
|
108
|
+
readonly roles: {
|
|
109
|
+
/** One page of roles; pass the previous `nextCursor` to continue. */
|
|
110
|
+
page: (orgId: string, actorRoleIds: string[], opts?: {
|
|
111
|
+
cursor?: string;
|
|
112
|
+
limit?: number;
|
|
113
|
+
}) => Promise<{
|
|
114
|
+
items: RoleView[];
|
|
115
|
+
nextCursor: string | null;
|
|
116
|
+
}>;
|
|
117
|
+
/** Every role, following the cursor (100 per request, at most 1,000 requests). */
|
|
118
|
+
list: (orgId: string, actorRoleIds: string[]) => Promise<RoleView[]>;
|
|
119
|
+
get: (orgId: string, actorRoleIds: string[], roleId: string) => Promise<RoleView>;
|
|
120
|
+
create: (orgId: string, actorRoleIds: string[], input: {
|
|
121
|
+
name: string;
|
|
122
|
+
description?: string;
|
|
123
|
+
grants: GrantInput[];
|
|
124
|
+
}) => Promise<RoleView>;
|
|
125
|
+
update: (orgId: string, actorRoleIds: string[], roleId: string, patch: {
|
|
126
|
+
name?: string;
|
|
127
|
+
description?: string;
|
|
128
|
+
}) => Promise<RoleView>;
|
|
129
|
+
setGrants: (orgId: string, actorRoleIds: string[], roleId: string, grants: GrantInput[]) => Promise<RoleView>;
|
|
130
|
+
reset: (orgId: string, actorRoleIds: string[], roleId: string) => Promise<RoleView>;
|
|
131
|
+
delete: (orgId: string, actorRoleIds: string[], roleId: string) => Promise<void>;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Keeps one stream to RBAC open (GET /v1/invalidations/stream) and drops cached role maps as RBAC
|
|
135
|
+
* reports changes. Reconnects on its own; every (re)connect clears the cache, since events sent
|
|
136
|
+
* while disconnected are not replayed. Idempotent: a call while subscribed is ignored, options included.
|
|
137
|
+
* `onEvent` hears each org and all event after the cache is cleared. Call close() on shutdown.
|
|
138
|
+
*/
|
|
139
|
+
subscribe(options?: SubscribeOptions): void;
|
|
140
|
+
/** Stops the invalidation stream and its reconnects. */
|
|
141
|
+
close(): void;
|
|
142
|
+
invalidate(orgId?: string): void;
|
|
143
|
+
private connectStream;
|
|
144
|
+
private armWatchdog;
|
|
145
|
+
private readStream;
|
|
146
|
+
private onStreamEvent;
|
|
147
|
+
/** The caller's handler must never break the stream, so its failures are only logged. */
|
|
148
|
+
private emit;
|
|
149
|
+
private rolesQuery;
|
|
150
|
+
private rolesPath;
|
|
151
|
+
private mutateRole;
|
|
152
|
+
/** The org's role map, or null when RBAC says the org does not exist. */
|
|
153
|
+
private roleMap;
|
|
154
|
+
private refresh;
|
|
155
|
+
private send;
|
|
156
|
+
private request;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** RBAC could not be reached (or refused our credentials) and no usable cached entry exists. Fail closed. */
|
|
160
|
+
declare class RbacUnavailableError extends Error {
|
|
161
|
+
readonly cause?: unknown | undefined;
|
|
162
|
+
readonly status = 503;
|
|
163
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
164
|
+
}
|
|
165
|
+
/** The permission is not granted. */
|
|
166
|
+
declare class RbacForbiddenError extends Error {
|
|
167
|
+
readonly reason: DenyReason;
|
|
168
|
+
readonly permission: string;
|
|
169
|
+
readonly status = 403;
|
|
170
|
+
constructor(reason: DenyReason, permission: string);
|
|
171
|
+
}
|
|
172
|
+
/** RBAC answered with an error (validation failure, escalation_denied, not found, ...). */
|
|
173
|
+
declare class RbacRequestError extends Error {
|
|
174
|
+
readonly status: number;
|
|
175
|
+
readonly code: string;
|
|
176
|
+
readonly details?: unknown | undefined;
|
|
177
|
+
constructor(status: number, code: string, message: string, details?: unknown | undefined);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The part of a response these handlers use. Express (and similar) responses satisfy it as is. */
|
|
181
|
+
interface RbacResponse {
|
|
182
|
+
status(code: number): RbacResponse;
|
|
183
|
+
json(body: unknown): unknown;
|
|
184
|
+
}
|
|
185
|
+
type Next = (err?: unknown) => void;
|
|
186
|
+
type SubjectOf<Req> = (req: Req) => Subject | null | undefined;
|
|
187
|
+
/** What requirePermission puts on `req.rbac` for the handler that follows. */
|
|
188
|
+
interface RbacContext {
|
|
189
|
+
scope: string | null;
|
|
190
|
+
params: Record<string, ParamValue>;
|
|
191
|
+
}
|
|
192
|
+
declare global {
|
|
193
|
+
namespace Express {
|
|
194
|
+
interface Request {
|
|
195
|
+
rbac?: RbacContext;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* 401 when the request has no subject, 403 when the permission is not granted,
|
|
201
|
+
* 503 when RBAC is unreachable beyond the stale window (fail closed).
|
|
202
|
+
* On allow, sets `req.rbac = { scope, params }`.
|
|
203
|
+
*/
|
|
204
|
+
declare function requirePermission<Req extends object>(client: RbacChecker, perm: string, subjectOf: SubjectOf<Req>): (req: Req & {
|
|
205
|
+
rbac?: RbacContext;
|
|
206
|
+
}, res: RbacResponse, next: Next) => Promise<void>;
|
|
207
|
+
/** Handler for `GET /api/me/permissions`. */
|
|
208
|
+
declare function permissionsHandler<Req extends object>(client: RbacChecker, subjectOf: SubjectOf<Req>): (req: Req, res: RbacResponse, next: Next) => Promise<void>;
|
|
209
|
+
|
|
210
|
+
interface MockRbacOptions {
|
|
211
|
+
product: string;
|
|
212
|
+
/** Declare scopes (narrowest first) and params for permissions that use them. Others are plain on/off. */
|
|
213
|
+
permissions?: Record<string, {
|
|
214
|
+
scopes?: string[];
|
|
215
|
+
params?: Record<string, ParamDef>;
|
|
216
|
+
}>;
|
|
217
|
+
/** roleId -> grants (shorthand like "invoices:read@team", or grant objects). */
|
|
218
|
+
roles: Record<string, (string | {
|
|
219
|
+
permission: string;
|
|
220
|
+
scope?: string | null;
|
|
221
|
+
params?: Record<string, ParamValue>;
|
|
222
|
+
})[]>;
|
|
223
|
+
/** Omit to treat every org as existing and active. */
|
|
224
|
+
orgs?: Record<string, {
|
|
225
|
+
status?: "active" | "suspended";
|
|
226
|
+
enabled?: boolean;
|
|
227
|
+
}>;
|
|
228
|
+
}
|
|
229
|
+
/** A no-network stand-in for RbacClient's check methods that uses the same decision code. */
|
|
230
|
+
declare function createMockRbac(opts: MockRbacOptions): RbacChecker;
|
|
231
|
+
|
|
232
|
+
interface SignAdminRequestOptions {
|
|
233
|
+
/** `ADMIN_ACTOR_SIGNING_SECRET`, shared with RBAC. Never sent over the wire. */
|
|
234
|
+
signingSecret: string;
|
|
235
|
+
method: string;
|
|
236
|
+
/** The path and query exactly as RBAC receives them: already percent-encoded, with no proxy prefix stripping or rewriting. */
|
|
237
|
+
url: string;
|
|
238
|
+
/** The staff member making the call. */
|
|
239
|
+
actor: string;
|
|
240
|
+
/** Milliseconds since the epoch. Defaults to `Date.now`. */
|
|
241
|
+
now?: () => number;
|
|
242
|
+
nonce?: string;
|
|
243
|
+
/** The exact string that will be sent as the request body. Default: no body. */
|
|
244
|
+
body?: string;
|
|
245
|
+
}
|
|
246
|
+
interface AdminSignatureHeaders {
|
|
247
|
+
"x-admin-actor": string;
|
|
248
|
+
"x-admin-timestamp": string;
|
|
249
|
+
"x-admin-nonce": string;
|
|
250
|
+
"x-admin-content-sha256": string;
|
|
251
|
+
"x-admin-signature": string;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Signs an admin request for RBAC. Send these headers with `Authorization: Bearer rba_...`.
|
|
255
|
+
* The canonical string is the same one the service verifies: timestamp, nonce, upper-case method,
|
|
256
|
+
* url, actor and the SHA-256 of the body joined by newlines.
|
|
257
|
+
*/
|
|
258
|
+
declare function signAdminRequest(o: SignAdminRequestOptions): AdminSignatureHeaders;
|
|
259
|
+
|
|
260
|
+
export { RbacClient, RbacForbiddenError, RbacRequestError, RbacUnavailableError, createMockRbac, permissionsHandler, requirePermission, signAdminRequest };
|
|
261
|
+
export type { AdminSignatureHeaders, ClientStats, GrantInput, InvalidationEvent, MockRbacOptions, Next, PermissionView, RbacChecker, RbacClientOptions, RbacContext, RbacResponse, RoleView, SignAdminRequestOptions, Subject, SubjectOf, SubscribeOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import {
|
|
3
|
+
decideFromRoleMap,
|
|
4
|
+
splitKey,
|
|
5
|
+
toFullKey
|
|
6
|
+
} from "@marichi-labs-tech/rbac-manifest-schema";
|
|
7
|
+
|
|
8
|
+
// src/cache.ts
|
|
9
|
+
var OrgCache = class {
|
|
10
|
+
entries = /* @__PURE__ */ new Map();
|
|
11
|
+
/** Bumped by every invalidation; a fetch that started earlier must not be cached. */
|
|
12
|
+
generation = 0;
|
|
13
|
+
get currentGeneration() {
|
|
14
|
+
return this.generation;
|
|
15
|
+
}
|
|
16
|
+
get(orgId) {
|
|
17
|
+
return this.entries.get(orgId);
|
|
18
|
+
}
|
|
19
|
+
set(orgId, entry) {
|
|
20
|
+
this.entries.set(orgId, entry);
|
|
21
|
+
}
|
|
22
|
+
drop(orgId) {
|
|
23
|
+
this.generation++;
|
|
24
|
+
this.entries.delete(orgId);
|
|
25
|
+
}
|
|
26
|
+
clear() {
|
|
27
|
+
this.generation++;
|
|
28
|
+
this.entries.clear();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/errors.ts
|
|
33
|
+
var RbacUnavailableError = class extends Error {
|
|
34
|
+
constructor(message, cause) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.cause = cause;
|
|
37
|
+
this.name = "RbacUnavailableError";
|
|
38
|
+
}
|
|
39
|
+
cause;
|
|
40
|
+
status = 503;
|
|
41
|
+
};
|
|
42
|
+
var RbacForbiddenError = class extends Error {
|
|
43
|
+
constructor(reason, permission) {
|
|
44
|
+
super(`Forbidden: ${permission} (${reason})`);
|
|
45
|
+
this.reason = reason;
|
|
46
|
+
this.permission = permission;
|
|
47
|
+
this.name = "RbacForbiddenError";
|
|
48
|
+
}
|
|
49
|
+
reason;
|
|
50
|
+
permission;
|
|
51
|
+
status = 403;
|
|
52
|
+
};
|
|
53
|
+
var RbacRequestError = class extends Error {
|
|
54
|
+
constructor(status, code, message, details) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.status = status;
|
|
57
|
+
this.code = code;
|
|
58
|
+
this.details = details;
|
|
59
|
+
this.name = "RbacRequestError";
|
|
60
|
+
}
|
|
61
|
+
status;
|
|
62
|
+
code;
|
|
63
|
+
details;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/client.ts
|
|
67
|
+
var NOT_FOUND_TTL_MS = 3e4;
|
|
68
|
+
var MAX_PAGES = 1e3;
|
|
69
|
+
var STREAM_WATCHDOG_MS = 6e4;
|
|
70
|
+
var BACKOFF_START_MS = 1e3;
|
|
71
|
+
var BACKOFF_CAP_MS = 3e4;
|
|
72
|
+
var RbacClient = class {
|
|
73
|
+
constructor(opts) {
|
|
74
|
+
this.opts = opts;
|
|
75
|
+
this.baseUrl = opts.url.replace(/\/+$/, "");
|
|
76
|
+
this.maxStaleMs = opts.maxStaleMs ?? 5 * 6e4;
|
|
77
|
+
this.timeoutMs = opts.timeoutMs ?? 5e3;
|
|
78
|
+
this.doFetch = opts.fetch ?? fetch;
|
|
79
|
+
this.now = opts.now ?? Date.now;
|
|
80
|
+
}
|
|
81
|
+
opts;
|
|
82
|
+
cache = new OrgCache();
|
|
83
|
+
counters = { checks: 0, allowed: 0, denied: 0, cacheHits: 0, cacheMisses: 0, staleServed: 0 };
|
|
84
|
+
inflight = /* @__PURE__ */ new Map();
|
|
85
|
+
baseUrl;
|
|
86
|
+
maxStaleMs;
|
|
87
|
+
timeoutMs;
|
|
88
|
+
doFetch;
|
|
89
|
+
now;
|
|
90
|
+
streamOn = false;
|
|
91
|
+
streamAbort;
|
|
92
|
+
streamRetry;
|
|
93
|
+
streamWatchdog;
|
|
94
|
+
streamAttempt = 0;
|
|
95
|
+
onEvent;
|
|
96
|
+
// ---- checks (local after the first fetch of an org) ----
|
|
97
|
+
/** Counters since construction, for the product's own metrics. */
|
|
98
|
+
stats() {
|
|
99
|
+
return { ...this.counters };
|
|
100
|
+
}
|
|
101
|
+
async resolve(subject, perm) {
|
|
102
|
+
const result = await this.decide(subject, perm);
|
|
103
|
+
this.counters.checks++;
|
|
104
|
+
if (result.allowed) this.counters.allowed++;
|
|
105
|
+
else this.counters.denied++;
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
async decide(subject, perm) {
|
|
109
|
+
const full = toFullKey(this.opts.product, perm);
|
|
110
|
+
const parts = splitKey(full);
|
|
111
|
+
if (!parts || parts.product !== this.opts.product) return { allowed: false, reason: "invalid_permission" };
|
|
112
|
+
const map = await this.roleMap(subject.orgId);
|
|
113
|
+
if (!map) return { allowed: false, reason: "org_not_found" };
|
|
114
|
+
return decideFromRoleMap(map, full, subject.roleIds);
|
|
115
|
+
}
|
|
116
|
+
async can(subject, perm) {
|
|
117
|
+
return (await this.resolve(subject, perm)).allowed;
|
|
118
|
+
}
|
|
119
|
+
async assert(subject, perm) {
|
|
120
|
+
const r = await this.resolve(subject, perm);
|
|
121
|
+
if (!r.allowed) throw new RbacForbiddenError(r.reason, perm);
|
|
122
|
+
}
|
|
123
|
+
async scope(subject, perm) {
|
|
124
|
+
const r = await this.resolve(subject, perm);
|
|
125
|
+
return r.allowed ? r.scope : null;
|
|
126
|
+
}
|
|
127
|
+
async param(subject, perm, name) {
|
|
128
|
+
const r = await this.resolve(subject, perm);
|
|
129
|
+
if (!r.allowed) return null;
|
|
130
|
+
return Object.hasOwn(r.params, name) ? r.params[name] : null;
|
|
131
|
+
}
|
|
132
|
+
/** Everything the subject may do in this product, for the frontend. */
|
|
133
|
+
async permissions(subject) {
|
|
134
|
+
const map = await this.roleMap(subject.orgId);
|
|
135
|
+
if (!map) return [];
|
|
136
|
+
const out = [];
|
|
137
|
+
for (const key of Object.keys(map.permissions).sort()) {
|
|
138
|
+
const r = decideFromRoleMap(map, key, subject.roleIds);
|
|
139
|
+
if (r.allowed) out.push({ key, scope: r.scope, params: r.params });
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
// ---- org lifecycle and role management (calls RBAC) ----
|
|
144
|
+
async ensureOrg(orgId, name) {
|
|
145
|
+
const body = await this.request(
|
|
146
|
+
"PUT",
|
|
147
|
+
`/v1/orgs/${encodeURIComponent(orgId)}`,
|
|
148
|
+
{ name }
|
|
149
|
+
);
|
|
150
|
+
this.invalidate(orgId);
|
|
151
|
+
return body;
|
|
152
|
+
}
|
|
153
|
+
async canAssign(orgId, actorRoleIds, roleIds) {
|
|
154
|
+
const res = await this.request(
|
|
155
|
+
"POST",
|
|
156
|
+
`/v1/authz/orgs/${encodeURIComponent(orgId)}/can-assign`,
|
|
157
|
+
{ actorRoleIds, roleIds }
|
|
158
|
+
);
|
|
159
|
+
return res.allowed === true;
|
|
160
|
+
}
|
|
161
|
+
roles = {
|
|
162
|
+
/** One page of roles; pass the previous `nextCursor` to continue. */
|
|
163
|
+
page: (orgId, actorRoleIds, opts = {}) => this.request("GET", this.rolesQuery(orgId, opts.limit ?? 50, opts.cursor), void 0, actorRoleIds),
|
|
164
|
+
/** Every role, following the cursor (100 per request, at most 1,000 requests). */
|
|
165
|
+
list: async (orgId, actorRoleIds) => {
|
|
166
|
+
const all = [];
|
|
167
|
+
let cursor;
|
|
168
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
169
|
+
const res = await this.roles.page(orgId, actorRoleIds, { limit: 100, ...cursor ? { cursor } : {} });
|
|
170
|
+
all.push(...res.items);
|
|
171
|
+
if (!res.nextCursor) return all;
|
|
172
|
+
cursor = res.nextCursor;
|
|
173
|
+
}
|
|
174
|
+
throw new RbacRequestError(0, "too_many_pages", `More than ${MAX_PAGES} pages of roles; use roles.page`);
|
|
175
|
+
},
|
|
176
|
+
get: (orgId, actorRoleIds, roleId) => this.request("GET", this.rolesPath(orgId, roleId), void 0, actorRoleIds),
|
|
177
|
+
create: (orgId, actorRoleIds, input) => this.mutateRole("POST", orgId, this.rolesPath(orgId), input, actorRoleIds),
|
|
178
|
+
update: (orgId, actorRoleIds, roleId, patch) => this.mutateRole("PATCH", orgId, this.rolesPath(orgId, roleId), patch, actorRoleIds),
|
|
179
|
+
setGrants: (orgId, actorRoleIds, roleId, grants) => this.mutateRole("PUT", orgId, `${this.rolesPath(orgId, roleId)}/grants`, { grants }, actorRoleIds),
|
|
180
|
+
reset: (orgId, actorRoleIds, roleId) => this.mutateRole("POST", orgId, `${this.rolesPath(orgId, roleId)}/reset`, void 0, actorRoleIds),
|
|
181
|
+
delete: async (orgId, actorRoleIds, roleId) => {
|
|
182
|
+
await this.mutateRole("DELETE", orgId, this.rolesPath(orgId, roleId), void 0, actorRoleIds);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
// ---- cache invalidation ----
|
|
186
|
+
/**
|
|
187
|
+
* Keeps one stream to RBAC open (GET /v1/invalidations/stream) and drops cached role maps as RBAC
|
|
188
|
+
* reports changes. Reconnects on its own; every (re)connect clears the cache, since events sent
|
|
189
|
+
* while disconnected are not replayed. Idempotent: a call while subscribed is ignored, options included.
|
|
190
|
+
* `onEvent` hears each org and all event after the cache is cleared. Call close() on shutdown.
|
|
191
|
+
*/
|
|
192
|
+
subscribe(options = {}) {
|
|
193
|
+
if (this.streamOn) {
|
|
194
|
+
if (options.onEvent && options.onEvent !== this.onEvent) {
|
|
195
|
+
this.opts.logger?.warn("rbac subscribe() called while already subscribed; its onEvent is ignored");
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.onEvent = options.onEvent;
|
|
200
|
+
this.streamOn = true;
|
|
201
|
+
this.streamAttempt = 0;
|
|
202
|
+
void this.connectStream();
|
|
203
|
+
}
|
|
204
|
+
/** Stops the invalidation stream and its reconnects. */
|
|
205
|
+
close() {
|
|
206
|
+
this.streamOn = false;
|
|
207
|
+
this.onEvent = void 0;
|
|
208
|
+
clearTimeout(this.streamRetry);
|
|
209
|
+
clearTimeout(this.streamWatchdog);
|
|
210
|
+
this.streamAbort?.abort();
|
|
211
|
+
}
|
|
212
|
+
invalidate(orgId) {
|
|
213
|
+
if (orgId === void 0) {
|
|
214
|
+
this.cache.clear();
|
|
215
|
+
this.inflight.clear();
|
|
216
|
+
} else {
|
|
217
|
+
this.cache.drop(orgId);
|
|
218
|
+
this.inflight.delete(orgId);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// ---- internals ----
|
|
222
|
+
async connectStream() {
|
|
223
|
+
const ac = new AbortController();
|
|
224
|
+
this.streamAbort = ac;
|
|
225
|
+
this.armWatchdog(ac);
|
|
226
|
+
try {
|
|
227
|
+
const res = await this.doFetch(`${this.baseUrl}/v1/invalidations/stream`, {
|
|
228
|
+
headers: { authorization: `Bearer ${this.opts.apiKey}`, accept: "text/event-stream" },
|
|
229
|
+
signal: ac.signal
|
|
230
|
+
});
|
|
231
|
+
if (res.status !== 200 || !res.body) {
|
|
232
|
+
const why = res.status === 401 || res.status === 403 ? "API key rejected" : "unexpected response";
|
|
233
|
+
this.opts.logger?.warn(`RBAC invalidation stream: ${why} (HTTP ${res.status}); retrying`);
|
|
234
|
+
await res.body?.cancel().catch(() => void 0);
|
|
235
|
+
} else {
|
|
236
|
+
await this.readStream(res.body, ac);
|
|
237
|
+
}
|
|
238
|
+
} catch (err) {
|
|
239
|
+
if (this.streamOn) this.opts.logger?.warn("RBAC invalidation stream disconnected; retrying", err);
|
|
240
|
+
} finally {
|
|
241
|
+
if (this.streamAbort === ac) clearTimeout(this.streamWatchdog);
|
|
242
|
+
}
|
|
243
|
+
if (!this.streamOn || this.streamAbort !== ac) return;
|
|
244
|
+
const delay = Math.random() * Math.min(BACKOFF_CAP_MS, BACKOFF_START_MS * 2 ** this.streamAttempt);
|
|
245
|
+
this.streamAttempt++;
|
|
246
|
+
this.streamRetry = setTimeout(() => void this.connectStream(), delay);
|
|
247
|
+
this.streamRetry.unref?.();
|
|
248
|
+
}
|
|
249
|
+
armWatchdog(ac) {
|
|
250
|
+
clearTimeout(this.streamWatchdog);
|
|
251
|
+
this.streamWatchdog = setTimeout(() => ac.abort(), STREAM_WATCHDOG_MS);
|
|
252
|
+
this.streamWatchdog.unref?.();
|
|
253
|
+
}
|
|
254
|
+
async readStream(body, ac) {
|
|
255
|
+
const reader = body.getReader();
|
|
256
|
+
const decoder = new TextDecoder();
|
|
257
|
+
let buf = "";
|
|
258
|
+
for (; ; ) {
|
|
259
|
+
const { done, value } = await reader.read();
|
|
260
|
+
if (done) return;
|
|
261
|
+
this.armWatchdog(ac);
|
|
262
|
+
buf += decoder.decode(value, { stream: true }).replace(/\r\n/g, "\n");
|
|
263
|
+
let end;
|
|
264
|
+
while ((end = buf.indexOf("\n\n")) >= 0) {
|
|
265
|
+
this.onStreamEvent(buf.slice(0, end));
|
|
266
|
+
buf = buf.slice(end + 2);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
onStreamEvent(block) {
|
|
271
|
+
const data = block.split("\n").filter((l) => l.startsWith("data:")).map((l) => l.slice(5).trimStart()).join("\n");
|
|
272
|
+
if (!data) return;
|
|
273
|
+
let m;
|
|
274
|
+
try {
|
|
275
|
+
m = JSON.parse(data);
|
|
276
|
+
} catch (err) {
|
|
277
|
+
this.opts.logger?.warn("ignoring malformed rbac invalidation message", err);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (m.type === "ready") {
|
|
281
|
+
this.streamAttempt = 0;
|
|
282
|
+
this.invalidate();
|
|
283
|
+
} else if (m.type === "org" && typeof m.orgId === "string") {
|
|
284
|
+
this.invalidate(m.orgId);
|
|
285
|
+
this.emit({ type: "org", orgId: m.orgId });
|
|
286
|
+
} else if (m.type === "all") {
|
|
287
|
+
this.invalidate();
|
|
288
|
+
this.emit({ type: "all" });
|
|
289
|
+
} else this.opts.logger?.warn("ignoring unknown rbac invalidation event");
|
|
290
|
+
}
|
|
291
|
+
/** The caller's handler must never break the stream, so its failures are only logged. */
|
|
292
|
+
emit(event) {
|
|
293
|
+
const handler = this.onEvent;
|
|
294
|
+
if (!handler) return;
|
|
295
|
+
const fail = (err) => this.opts.logger?.warn("rbac onEvent handler failed", err);
|
|
296
|
+
try {
|
|
297
|
+
const result = handler(event);
|
|
298
|
+
if (result) Promise.resolve(result).catch(fail);
|
|
299
|
+
} catch (err) {
|
|
300
|
+
fail(err);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
rolesQuery(orgId, limit, cursor) {
|
|
304
|
+
return `${this.rolesPath(orgId)}?limit=${limit}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`;
|
|
305
|
+
}
|
|
306
|
+
rolesPath(orgId, roleId) {
|
|
307
|
+
const base = `/v1/orgs/${encodeURIComponent(orgId)}/roles`;
|
|
308
|
+
return roleId === void 0 ? base : `${base}/${encodeURIComponent(roleId)}`;
|
|
309
|
+
}
|
|
310
|
+
async mutateRole(method, orgId, path, body, actor) {
|
|
311
|
+
const res = await this.request(method, path, body, actor);
|
|
312
|
+
this.invalidate(orgId);
|
|
313
|
+
return res;
|
|
314
|
+
}
|
|
315
|
+
/** The org's role map, or null when RBAC says the org does not exist. */
|
|
316
|
+
async roleMap(orgId) {
|
|
317
|
+
const entry = this.cache.get(orgId);
|
|
318
|
+
if (entry && this.now() < entry.expiresAt) {
|
|
319
|
+
this.counters.cacheHits++;
|
|
320
|
+
return entry.kind === "map" ? entry.map : null;
|
|
321
|
+
}
|
|
322
|
+
const existing = this.inflight.get(orgId);
|
|
323
|
+
if (existing) return existing;
|
|
324
|
+
this.counters.cacheMisses++;
|
|
325
|
+
const p = this.refresh(orgId, entry).finally(() => {
|
|
326
|
+
if (this.inflight.get(orgId) === p) this.inflight.delete(orgId);
|
|
327
|
+
});
|
|
328
|
+
this.inflight.set(orgId, p);
|
|
329
|
+
return p;
|
|
330
|
+
}
|
|
331
|
+
async refresh(orgId, stale) {
|
|
332
|
+
const generation = this.cache.currentGeneration;
|
|
333
|
+
try {
|
|
334
|
+
const res = await this.send("GET", `/v1/authz/orgs/${encodeURIComponent(orgId)}/role-permissions`);
|
|
335
|
+
if (res.status === 404) {
|
|
336
|
+
const body = await safeJson(res);
|
|
337
|
+
if (body?.error === "org_not_found") {
|
|
338
|
+
if (this.cache.currentGeneration === generation) {
|
|
339
|
+
this.cache.set(orgId, { kind: "org_not_found", expiresAt: this.now() + NOT_FOUND_TTL_MS });
|
|
340
|
+
}
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (res.status === 401 || res.status === 403) {
|
|
345
|
+
throw new RbacUnavailableError(`RBAC rejected the API key (HTTP ${res.status})`);
|
|
346
|
+
}
|
|
347
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
348
|
+
const map = await res.json();
|
|
349
|
+
if (this.cache.currentGeneration === generation) {
|
|
350
|
+
this.cache.set(orgId, { kind: "map", map, expiresAt: this.now() + map.ttl * 1e3 });
|
|
351
|
+
}
|
|
352
|
+
return map;
|
|
353
|
+
} catch (err) {
|
|
354
|
+
if (err instanceof RbacUnavailableError) throw err;
|
|
355
|
+
const stillValid = this.cache.currentGeneration === generation;
|
|
356
|
+
if (stillValid && stale && stale.kind === "map" && this.now() - stale.expiresAt <= this.maxStaleMs) {
|
|
357
|
+
this.counters.staleServed++;
|
|
358
|
+
this.opts.logger?.warn(`RBAC unreachable; serving stale role map for org ${orgId}`, err);
|
|
359
|
+
return stale.map;
|
|
360
|
+
}
|
|
361
|
+
throw new RbacUnavailableError("RBAC is unreachable and no usable cached role map exists", err);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
send(method, path, body, actorRoleIds) {
|
|
365
|
+
const headers = { authorization: `Bearer ${this.opts.apiKey}` };
|
|
366
|
+
if (body !== void 0) headers["content-type"] = "application/json";
|
|
367
|
+
if (actorRoleIds) headers["x-actor-role-ids"] = actorRoleIds.join(",");
|
|
368
|
+
return this.doFetch(`${this.baseUrl}${path}`, {
|
|
369
|
+
method,
|
|
370
|
+
headers,
|
|
371
|
+
// Without a deadline a server that never answers would hang every check for this org,
|
|
372
|
+
// and neither the stale fallback nor the 503 would ever apply. Covers reading the body too.
|
|
373
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
374
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
async request(method, path, body, actorRoleIds) {
|
|
378
|
+
let res;
|
|
379
|
+
try {
|
|
380
|
+
res = await this.send(method, path, body, actorRoleIds);
|
|
381
|
+
} catch (err) {
|
|
382
|
+
throw new RbacUnavailableError("RBAC is unreachable", err);
|
|
383
|
+
}
|
|
384
|
+
if (res.status >= 500) throw new RbacUnavailableError(`RBAC failed (HTTP ${res.status})`);
|
|
385
|
+
if (!res.ok) {
|
|
386
|
+
const e = await safeJson(res);
|
|
387
|
+
throw new RbacRequestError(res.status, e?.error ?? "request_failed", e?.message ?? `HTTP ${res.status}`, e?.details);
|
|
388
|
+
}
|
|
389
|
+
if (res.status === 204) return void 0;
|
|
390
|
+
return await res.json();
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
async function safeJson(res) {
|
|
394
|
+
try {
|
|
395
|
+
return await res.json();
|
|
396
|
+
} catch {
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/middleware.ts
|
|
402
|
+
function requirePermission(client, perm, subjectOf) {
|
|
403
|
+
return async (req, res, next) => {
|
|
404
|
+
const subject = subjectOf(req);
|
|
405
|
+
if (!subject) {
|
|
406
|
+
res.status(401).json({ error: "unauthenticated" });
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
try {
|
|
410
|
+
const r = await client.resolve(subject, perm);
|
|
411
|
+
if (!r.allowed) {
|
|
412
|
+
res.status(403).json({ error: "forbidden", reason: r.reason });
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
req.rbac = { scope: r.scope, params: r.params };
|
|
416
|
+
next();
|
|
417
|
+
} catch (err) {
|
|
418
|
+
if (err instanceof RbacUnavailableError) {
|
|
419
|
+
res.status(503).json({ error: "authz_unavailable" });
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
next(err);
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
function permissionsHandler(client, subjectOf) {
|
|
427
|
+
return async (req, res, next) => {
|
|
428
|
+
const subject = subjectOf(req);
|
|
429
|
+
if (!subject) {
|
|
430
|
+
res.status(401).json({ error: "unauthenticated" });
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
try {
|
|
434
|
+
res.json({ permissions: await client.permissions(subject) });
|
|
435
|
+
} catch (err) {
|
|
436
|
+
if (err instanceof RbacUnavailableError) {
|
|
437
|
+
res.status(503).json({ error: "authz_unavailable" });
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
next(err);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/mock.ts
|
|
446
|
+
import {
|
|
447
|
+
decideFromRoleMap as decideFromRoleMap2,
|
|
448
|
+
expandGrant,
|
|
449
|
+
parseGrant,
|
|
450
|
+
splitKey as splitKey2,
|
|
451
|
+
toFullKey as toFullKey2
|
|
452
|
+
} from "@marichi-labs-tech/rbac-manifest-schema";
|
|
453
|
+
function createMockRbac(opts) {
|
|
454
|
+
const { product } = opts;
|
|
455
|
+
const defs = /* @__PURE__ */ new Map();
|
|
456
|
+
const add = (key, scopes = [], params = {}) => {
|
|
457
|
+
const parts = splitKey2(key);
|
|
458
|
+
if (!parts) return;
|
|
459
|
+
defs.set(key, { key, product, feature: parts.feature, action: parts.action, scopes, params, deprecated: false });
|
|
460
|
+
};
|
|
461
|
+
for (const [k, v] of Object.entries(opts.permissions ?? {})) add(toFullKey2(product, k), v.scopes, v.params);
|
|
462
|
+
const roleGrants = {};
|
|
463
|
+
for (const [id, list] of Object.entries(opts.roles)) {
|
|
464
|
+
roleGrants[id] = list.map((g) => parseGrant(product, g));
|
|
465
|
+
for (const g of roleGrants[id]) if (!g.permission.endsWith("*") && !defs.has(g.permission)) add(g.permission);
|
|
466
|
+
}
|
|
467
|
+
const active = [...defs.values()];
|
|
468
|
+
const expanded = Object.fromEntries(
|
|
469
|
+
Object.entries(roleGrants).map(([id, gs]) => [id, gs.flatMap((g) => expandGrant(g, active))])
|
|
470
|
+
);
|
|
471
|
+
const mapFor = (orgId) => {
|
|
472
|
+
const org = opts.orgs?.[orgId];
|
|
473
|
+
if (opts.orgs && !org) return null;
|
|
474
|
+
return {
|
|
475
|
+
orgId,
|
|
476
|
+
orgStatus: org?.status ?? "active",
|
|
477
|
+
productEnabled: org?.enabled ?? true,
|
|
478
|
+
ttl: 300,
|
|
479
|
+
permissions: Object.fromEntries(active.map((d) => [d.key, { scopes: d.scopes, params: d.params }])),
|
|
480
|
+
roles: expanded
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
const resolve = async (s, perm) => {
|
|
484
|
+
const full = toFullKey2(product, perm);
|
|
485
|
+
const parts = splitKey2(full);
|
|
486
|
+
if (!parts || parts.product !== product) return { allowed: false, reason: "invalid_permission" };
|
|
487
|
+
const map = mapFor(s.orgId);
|
|
488
|
+
if (!map) return { allowed: false, reason: "org_not_found" };
|
|
489
|
+
return decideFromRoleMap2(map, full, s.roleIds);
|
|
490
|
+
};
|
|
491
|
+
return {
|
|
492
|
+
resolve,
|
|
493
|
+
can: async (s, p) => (await resolve(s, p)).allowed,
|
|
494
|
+
async assert(s, p) {
|
|
495
|
+
const r = await resolve(s, p);
|
|
496
|
+
if (!r.allowed) throw new RbacForbiddenError(r.reason, p);
|
|
497
|
+
},
|
|
498
|
+
async scope(s, p) {
|
|
499
|
+
const r = await resolve(s, p);
|
|
500
|
+
return r.allowed ? r.scope : null;
|
|
501
|
+
},
|
|
502
|
+
async param(s, p, name) {
|
|
503
|
+
const r = await resolve(s, p);
|
|
504
|
+
return r.allowed && Object.hasOwn(r.params, name) ? r.params[name] : null;
|
|
505
|
+
},
|
|
506
|
+
async permissions(s) {
|
|
507
|
+
const out = [];
|
|
508
|
+
for (const d of active) {
|
|
509
|
+
const r = await resolve(s, d.key);
|
|
510
|
+
if (r.allowed) out.push({ key: d.key, scope: r.scope, params: r.params });
|
|
511
|
+
}
|
|
512
|
+
return out.sort((a, b) => a.key.localeCompare(b.key));
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// src/admin-signature.ts
|
|
518
|
+
import { createHash, createHmac, randomBytes } from "crypto";
|
|
519
|
+
function signAdminRequest(o) {
|
|
520
|
+
const timestamp = String(Math.floor((o.now ?? Date.now)() / 1e3));
|
|
521
|
+
const nonce = o.nonce ?? randomBytes(24).toString("base64url");
|
|
522
|
+
const contentSha256 = createHash("sha256").update(o.body ?? "").digest("hex");
|
|
523
|
+
const canonical = [timestamp, nonce, o.method.toUpperCase(), o.url, o.actor, contentSha256].join("\n");
|
|
524
|
+
return {
|
|
525
|
+
"x-admin-actor": o.actor,
|
|
526
|
+
"x-admin-timestamp": timestamp,
|
|
527
|
+
"x-admin-nonce": nonce,
|
|
528
|
+
"x-admin-content-sha256": contentSha256,
|
|
529
|
+
"x-admin-signature": createHmac("sha256", o.signingSecret).update(canonical).digest("hex")
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
export {
|
|
533
|
+
RbacClient,
|
|
534
|
+
RbacForbiddenError,
|
|
535
|
+
RbacRequestError,
|
|
536
|
+
RbacUnavailableError,
|
|
537
|
+
createMockRbac,
|
|
538
|
+
permissionsHandler,
|
|
539
|
+
requirePermission,
|
|
540
|
+
signAdminRequest
|
|
541
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marichi-labs-tech/rbac-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Marichi-Labs-Tech/rbac.git",
|
|
9
|
+
"directory": "packages/rbac-sdk"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"registry": "https://registry.npmjs.org",
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@marichi-labs-tech/rbac-manifest-schema": "0.2.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsup",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
}
|
|
6
34
|
}
|
package/README.md
DELETED