@lepistabioinformatics/mycelium-sdk 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.
@@ -0,0 +1,463 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const KNOWN_KEYS: readonly ["phone_number", "telegram_user", "whatsapp_user", "locale"];
4
+ type AccountMetaKey = (typeof KNOWN_KEYS)[number] | `custom:${string}`;
5
+ declare const AccountMetaKeySchema: z.ZodEffects<z.ZodString, AccountMetaKey, string>;
6
+ declare const ProfileMetaSchema: z.ZodRecord<z.ZodEffects<z.ZodString, AccountMetaKey, string>, z.ZodString>;
7
+ type ProfileMeta = z.infer<typeof ProfileMetaSchema>;
8
+
9
+ declare const Permission: {
10
+ readonly READ: 0;
11
+ readonly WRITE: 1;
12
+ };
13
+ type Permission = (typeof Permission)[keyof typeof Permission];
14
+ declare const PermissionSchema: z.ZodType<Permission>;
15
+ declare function permissionToInt(permission: Permission): number;
16
+ declare function permissionFromInt(value: number): Permission;
17
+
18
+ declare const LicensedResourceSchema: z.ZodObject<{
19
+ accId: z.ZodString;
20
+ sysAcc: z.ZodBoolean;
21
+ tenantId: z.ZodString;
22
+ accName: z.ZodString;
23
+ role: z.ZodString;
24
+ roleId: z.ZodString;
25
+ perm: z.ZodType<Permission, z.ZodTypeDef, Permission>;
26
+ verified: z.ZodBoolean;
27
+ permitFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
28
+ denyFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ verified: boolean;
31
+ accId: string;
32
+ sysAcc: boolean;
33
+ tenantId: string;
34
+ accName: string;
35
+ role: string;
36
+ roleId: string;
37
+ perm: Permission;
38
+ permitFlags?: string[] | undefined;
39
+ denyFlags?: string[] | undefined;
40
+ }, {
41
+ verified: boolean;
42
+ accId: string;
43
+ sysAcc: boolean;
44
+ tenantId: string;
45
+ accName: string;
46
+ role: string;
47
+ roleId: string;
48
+ perm: Permission;
49
+ permitFlags?: string[] | undefined;
50
+ denyFlags?: string[] | undefined;
51
+ }>;
52
+ type LicensedResource = z.infer<typeof LicensedResourceSchema>;
53
+ declare function licensedResourceFromUrlString(value: string): LicensedResource;
54
+
55
+ declare const LicensedResourcesSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
56
+ kind: z.ZodLiteral<"records">;
57
+ records: z.ZodArray<z.ZodObject<{
58
+ accId: z.ZodString;
59
+ sysAcc: z.ZodBoolean;
60
+ tenantId: z.ZodString;
61
+ accName: z.ZodString;
62
+ role: z.ZodString;
63
+ roleId: z.ZodString;
64
+ perm: z.ZodType<Permission, z.ZodTypeDef, Permission>;
65
+ verified: z.ZodBoolean;
66
+ permitFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
67
+ denyFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
68
+ }, "strip", z.ZodTypeAny, {
69
+ verified: boolean;
70
+ accId: string;
71
+ sysAcc: boolean;
72
+ tenantId: string;
73
+ accName: string;
74
+ role: string;
75
+ roleId: string;
76
+ perm: Permission;
77
+ permitFlags?: string[] | undefined;
78
+ denyFlags?: string[] | undefined;
79
+ }, {
80
+ verified: boolean;
81
+ accId: string;
82
+ sysAcc: boolean;
83
+ tenantId: string;
84
+ accName: string;
85
+ role: string;
86
+ roleId: string;
87
+ perm: Permission;
88
+ permitFlags?: string[] | undefined;
89
+ denyFlags?: string[] | undefined;
90
+ }>, "many">;
91
+ }, "strip", z.ZodTypeAny, {
92
+ records: {
93
+ verified: boolean;
94
+ accId: string;
95
+ sysAcc: boolean;
96
+ tenantId: string;
97
+ accName: string;
98
+ role: string;
99
+ roleId: string;
100
+ perm: Permission;
101
+ permitFlags?: string[] | undefined;
102
+ denyFlags?: string[] | undefined;
103
+ }[];
104
+ kind: "records";
105
+ }, {
106
+ records: {
107
+ verified: boolean;
108
+ accId: string;
109
+ sysAcc: boolean;
110
+ tenantId: string;
111
+ accName: string;
112
+ role: string;
113
+ roleId: string;
114
+ perm: Permission;
115
+ permitFlags?: string[] | undefined;
116
+ denyFlags?: string[] | undefined;
117
+ }[];
118
+ kind: "records";
119
+ }>, z.ZodObject<{
120
+ kind: z.ZodLiteral<"urls">;
121
+ urls: z.ZodArray<z.ZodString, "many">;
122
+ }, "strip", z.ZodTypeAny, {
123
+ urls: string[];
124
+ kind: "urls";
125
+ }, {
126
+ urls: string[];
127
+ kind: "urls";
128
+ }>]>, {
129
+ records: {
130
+ verified: boolean;
131
+ accId: string;
132
+ sysAcc: boolean;
133
+ tenantId: string;
134
+ accName: string;
135
+ role: string;
136
+ roleId: string;
137
+ perm: Permission;
138
+ permitFlags?: string[] | undefined;
139
+ denyFlags?: string[] | undefined;
140
+ }[];
141
+ kind: "records";
142
+ } | {
143
+ urls: string[];
144
+ kind: "urls";
145
+ }, unknown>;
146
+ type LicensedResources = z.infer<typeof LicensedResourcesSchema>;
147
+ declare function toLicensesVector(lr: LicensedResources | undefined): LicensedResource[];
148
+
149
+ type RelatedAccounts = {
150
+ kind: "AllowedAccounts";
151
+ accounts: string[];
152
+ } | {
153
+ kind: "HasTenantWidePrivileges";
154
+ tenantId: string;
155
+ } | {
156
+ kind: "HasStaffPrivileges";
157
+ } | {
158
+ kind: "HasManagerPrivileges";
159
+ };
160
+
161
+ declare const ProfileSchema: z.ZodObject<{
162
+ owners: z.ZodDefault<z.ZodArray<z.ZodObject<{
163
+ id: z.ZodString;
164
+ email: z.ZodString;
165
+ firstName: z.ZodOptional<z.ZodString>;
166
+ lastName: z.ZodOptional<z.ZodString>;
167
+ username: z.ZodOptional<z.ZodString>;
168
+ isPrincipal: z.ZodBoolean;
169
+ }, "strip", z.ZodTypeAny, {
170
+ email: string;
171
+ id: string;
172
+ isPrincipal: boolean;
173
+ firstName?: string | undefined;
174
+ lastName?: string | undefined;
175
+ username?: string | undefined;
176
+ }, {
177
+ email: string;
178
+ id: string;
179
+ isPrincipal: boolean;
180
+ firstName?: string | undefined;
181
+ lastName?: string | undefined;
182
+ username?: string | undefined;
183
+ }>, "many">>;
184
+ accId: z.ZodString;
185
+ isSubscription: z.ZodBoolean;
186
+ isStaff: z.ZodBoolean;
187
+ isManager: z.ZodDefault<z.ZodBoolean>;
188
+ ownerIsActive: z.ZodBoolean;
189
+ accountIsActive: z.ZodBoolean;
190
+ accountWasApproved: z.ZodBoolean;
191
+ accountWasArchived: z.ZodBoolean;
192
+ accountWasDeleted: z.ZodBoolean;
193
+ verboseStatus: z.ZodOptional<z.ZodEnum<["unverified", "verified", "inactive", "archived", "deleted", "unknown"]>>;
194
+ licensedResources: z.ZodOptional<z.ZodEffects<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
195
+ kind: z.ZodLiteral<"records">;
196
+ records: z.ZodArray<z.ZodObject<{
197
+ accId: z.ZodString;
198
+ sysAcc: z.ZodBoolean;
199
+ tenantId: z.ZodString;
200
+ accName: z.ZodString;
201
+ role: z.ZodString;
202
+ roleId: z.ZodString;
203
+ perm: z.ZodType<Permission, z.ZodTypeDef, Permission>;
204
+ verified: z.ZodBoolean;
205
+ permitFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
206
+ denyFlags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
207
+ }, "strip", z.ZodTypeAny, {
208
+ verified: boolean;
209
+ accId: string;
210
+ sysAcc: boolean;
211
+ tenantId: string;
212
+ accName: string;
213
+ role: string;
214
+ roleId: string;
215
+ perm: Permission;
216
+ permitFlags?: string[] | undefined;
217
+ denyFlags?: string[] | undefined;
218
+ }, {
219
+ verified: boolean;
220
+ accId: string;
221
+ sysAcc: boolean;
222
+ tenantId: string;
223
+ accName: string;
224
+ role: string;
225
+ roleId: string;
226
+ perm: Permission;
227
+ permitFlags?: string[] | undefined;
228
+ denyFlags?: string[] | undefined;
229
+ }>, "many">;
230
+ }, "strip", z.ZodTypeAny, {
231
+ records: {
232
+ verified: boolean;
233
+ accId: string;
234
+ sysAcc: boolean;
235
+ tenantId: string;
236
+ accName: string;
237
+ role: string;
238
+ roleId: string;
239
+ perm: Permission;
240
+ permitFlags?: string[] | undefined;
241
+ denyFlags?: string[] | undefined;
242
+ }[];
243
+ kind: "records";
244
+ }, {
245
+ records: {
246
+ verified: boolean;
247
+ accId: string;
248
+ sysAcc: boolean;
249
+ tenantId: string;
250
+ accName: string;
251
+ role: string;
252
+ roleId: string;
253
+ perm: Permission;
254
+ permitFlags?: string[] | undefined;
255
+ denyFlags?: string[] | undefined;
256
+ }[];
257
+ kind: "records";
258
+ }>, z.ZodObject<{
259
+ kind: z.ZodLiteral<"urls">;
260
+ urls: z.ZodArray<z.ZodString, "many">;
261
+ }, "strip", z.ZodTypeAny, {
262
+ urls: string[];
263
+ kind: "urls";
264
+ }, {
265
+ urls: string[];
266
+ kind: "urls";
267
+ }>]>, {
268
+ records: {
269
+ verified: boolean;
270
+ accId: string;
271
+ sysAcc: boolean;
272
+ tenantId: string;
273
+ accName: string;
274
+ role: string;
275
+ roleId: string;
276
+ perm: Permission;
277
+ permitFlags?: string[] | undefined;
278
+ denyFlags?: string[] | undefined;
279
+ }[];
280
+ kind: "records";
281
+ } | {
282
+ urls: string[];
283
+ kind: "urls";
284
+ }, unknown>>;
285
+ tenantsOwnership: z.ZodOptional<z.ZodEffects<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
286
+ kind: z.ZodLiteral<"records">;
287
+ records: z.ZodArray<z.ZodObject<{
288
+ id: z.ZodString;
289
+ name: z.ZodString;
290
+ since: z.ZodDate;
291
+ }, "strip", z.ZodTypeAny, {
292
+ id: string;
293
+ name: string;
294
+ since: Date;
295
+ }, {
296
+ id: string;
297
+ name: string;
298
+ since: Date;
299
+ }>, "many">;
300
+ }, "strip", z.ZodTypeAny, {
301
+ records: {
302
+ id: string;
303
+ name: string;
304
+ since: Date;
305
+ }[];
306
+ kind: "records";
307
+ }, {
308
+ records: {
309
+ id: string;
310
+ name: string;
311
+ since: Date;
312
+ }[];
313
+ kind: "records";
314
+ }>, z.ZodObject<{
315
+ kind: z.ZodLiteral<"urls">;
316
+ urls: z.ZodArray<z.ZodString, "many">;
317
+ }, "strip", z.ZodTypeAny, {
318
+ urls: string[];
319
+ kind: "urls";
320
+ }, {
321
+ urls: string[];
322
+ kind: "urls";
323
+ }>]>, {
324
+ records: {
325
+ id: string;
326
+ name: string;
327
+ since: Date;
328
+ }[];
329
+ kind: "records";
330
+ } | {
331
+ urls: string[];
332
+ kind: "urls";
333
+ }, unknown>>;
334
+ meta: z.ZodOptional<z.ZodRecord<z.ZodEffects<z.ZodString, AccountMetaKey, string>, z.ZodString>>;
335
+ filteringState: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
336
+ }, "strip", z.ZodTypeAny, {
337
+ accId: string;
338
+ owners: {
339
+ email: string;
340
+ id: string;
341
+ isPrincipal: boolean;
342
+ firstName?: string | undefined;
343
+ lastName?: string | undefined;
344
+ username?: string | undefined;
345
+ }[];
346
+ isSubscription: boolean;
347
+ isStaff: boolean;
348
+ isManager: boolean;
349
+ ownerIsActive: boolean;
350
+ accountIsActive: boolean;
351
+ accountWasApproved: boolean;
352
+ accountWasArchived: boolean;
353
+ accountWasDeleted: boolean;
354
+ verboseStatus?: "unknown" | "unverified" | "verified" | "inactive" | "archived" | "deleted" | undefined;
355
+ licensedResources?: {
356
+ records: {
357
+ verified: boolean;
358
+ accId: string;
359
+ sysAcc: boolean;
360
+ tenantId: string;
361
+ accName: string;
362
+ role: string;
363
+ roleId: string;
364
+ perm: Permission;
365
+ permitFlags?: string[] | undefined;
366
+ denyFlags?: string[] | undefined;
367
+ }[];
368
+ kind: "records";
369
+ } | {
370
+ urls: string[];
371
+ kind: "urls";
372
+ } | undefined;
373
+ tenantsOwnership?: {
374
+ records: {
375
+ id: string;
376
+ name: string;
377
+ since: Date;
378
+ }[];
379
+ kind: "records";
380
+ } | {
381
+ urls: string[];
382
+ kind: "urls";
383
+ } | undefined;
384
+ meta?: Partial<Record<AccountMetaKey, string>> | undefined;
385
+ filteringState?: string[] | undefined;
386
+ }, {
387
+ accId: string;
388
+ isSubscription: boolean;
389
+ isStaff: boolean;
390
+ ownerIsActive: boolean;
391
+ accountIsActive: boolean;
392
+ accountWasApproved: boolean;
393
+ accountWasArchived: boolean;
394
+ accountWasDeleted: boolean;
395
+ owners?: {
396
+ email: string;
397
+ id: string;
398
+ isPrincipal: boolean;
399
+ firstName?: string | undefined;
400
+ lastName?: string | undefined;
401
+ username?: string | undefined;
402
+ }[] | undefined;
403
+ isManager?: boolean | undefined;
404
+ verboseStatus?: "unknown" | "unverified" | "verified" | "inactive" | "archived" | "deleted" | undefined;
405
+ licensedResources?: unknown;
406
+ tenantsOwnership?: unknown;
407
+ meta?: Record<string, string> | undefined;
408
+ filteringState?: string[] | undefined;
409
+ }>;
410
+ type ProfileData = z.infer<typeof ProfileSchema>;
411
+ declare class Profile {
412
+ readonly data: ProfileData;
413
+ private constructor();
414
+ static fromValidated(data: ProfileData): Profile;
415
+ get accId(): string;
416
+ get owners(): {
417
+ email: string;
418
+ id: string;
419
+ isPrincipal: boolean;
420
+ firstName?: string | undefined;
421
+ lastName?: string | undefined;
422
+ username?: string | undefined;
423
+ }[];
424
+ get isStaff(): boolean;
425
+ get isManager(): boolean;
426
+ get licensedResources(): LicensedResources | undefined;
427
+ get tenantsOwnership(): {
428
+ records: {
429
+ id: string;
430
+ name: string;
431
+ since: Date;
432
+ }[];
433
+ kind: "records";
434
+ } | {
435
+ urls: string[];
436
+ kind: "urls";
437
+ } | undefined;
438
+ get filteringState(): string[] | undefined;
439
+ private withData;
440
+ private filterLicensedResources;
441
+ private withPermission;
442
+ withReadAccess(): Profile;
443
+ withWriteAccess(): Profile;
444
+ onTenant(tenantId: string): Profile;
445
+ withRoles(roles: string[]): Profile;
446
+ onAccount(accountId: string): Profile;
447
+ hasPermitFlags(flags: string[]): Profile;
448
+ hasNotDenyFlags(flags: string[]): Profile;
449
+ onTenantAsManager(tenantId: string, permission: Permission): Profile;
450
+ withSystemAccountsAccess(): Profile;
451
+ withTenantOwnershipOrError(tenantId: string): Profile;
452
+ hasAdminPrivileges(): boolean;
453
+ hasAdminPrivilegesOrError(): void;
454
+ getIdsOrError(): string[];
455
+ getTenantWidePermissionOrError(tenantId: string, permission: Permission): RelatedAccounts;
456
+ getRelatedAccountsOrTenantWidePermissionOrError(tenantId: string, permission: Permission): RelatedAccounts;
457
+ getRelatedAccountOrError(): RelatedAccounts;
458
+ getOwnersIds(): string[];
459
+ profileString(): string;
460
+ profileRedacted(): string;
461
+ }
462
+
463
+ export { type AccountMetaKey as A, type LicensedResource as L, Profile as P, type RelatedAccounts as R, AccountMetaKeySchema as a, LicensedResourceSchema as b, type LicensedResources as c, LicensedResourcesSchema as d, Permission as e, PermissionSchema as f, type ProfileData as g, type ProfileMeta as h, ProfileMetaSchema as i, ProfileSchema as j, permissionToInt as k, licensedResourceFromUrlString as l, permissionFromInt as p, toLicensesVector as t };
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@lepistabioinformatics/mycelium-sdk",
3
+ "version": "2.0.0",
4
+ "description": "Mycelium SDK for Node.js/TypeScript backends — decode the x-mycelium-profile header and enforce tenant/account/role authorization with a fluent, typed API",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=23.8.0"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
18
+ },
19
+ "./express": {
20
+ "types": "./dist/express/index.d.ts",
21
+ "import": "./dist/express/index.js",
22
+ "require": "./dist/express/index.cjs"
23
+ },
24
+ "./fastify": {
25
+ "types": "./dist/fastify/index.d.ts",
26
+ "import": "./dist/fastify/index.js",
27
+ "require": "./dist/fastify/index.cjs"
28
+ }
29
+ },
30
+ "main": "./dist/index.cjs",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "typecheck": "tsc --noEmit",
36
+ "test": "vitest",
37
+ "lint": "eslint src",
38
+ "prepublishOnly": "yarn build"
39
+ },
40
+ "dependencies": {
41
+ "zod": "^3.24.0"
42
+ },
43
+ "peerDependencies": {
44
+ "express": ">=4.18.0",
45
+ "fastify": ">=4.0.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "express": {
49
+ "optional": true
50
+ },
51
+ "fastify": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "devDependencies": {
56
+ "@types/express": "^4.17.21",
57
+ "@types/node": "^24.0.0",
58
+ "@types/supertest": "^6.0.2",
59
+ "eslint": "^9.15.0",
60
+ "fastify": "^4.28.0",
61
+ "fastify-plugin": "^5.0.1",
62
+ "express": "^4.21.0",
63
+ "prettier": "^3.4.0",
64
+ "supertest": "^7.0.0",
65
+ "tsup": "^8.3.0",
66
+ "typescript": "^5.7.0",
67
+ "typescript-eslint": "^8.15.0",
68
+ "vitest": "^3.2.6",
69
+ "semantic-release": "^25.0.6",
70
+ "conventional-changelog-conventionalcommits": "^8.0.0",
71
+ "@semantic-release/changelog": "^6.0.3",
72
+ "@semantic-release/git": "^10.0.1",
73
+ "@commitlint/cli": "^19.6.0",
74
+ "@commitlint/config-conventional": "^19.6.0"
75
+ },
76
+ "resolutions": {
77
+ "fast-uri": "^3.1.2"
78
+ },
79
+ "repository": {
80
+ "type": "git",
81
+ "url": "https://github.com/LepistaBioinformatics/mycelium-sdk-js.git"
82
+ },
83
+ "publishConfig": {
84
+ "access": "public"
85
+ }
86
+ }