@lssm/lib.files 0.0.0-canary-20251206160926

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.
Files changed (114) hide show
  1. package/README.md +183 -0
  2. package/dist/contracts/dist/capabilities/openbanking.js +1 -0
  3. package/dist/contracts/dist/client/index.js +1 -0
  4. package/dist/contracts/dist/client/react/feature-render.js +1 -0
  5. package/dist/contracts/dist/client/react/form-render.js +1 -0
  6. package/dist/contracts/dist/client/react/index.js +1 -0
  7. package/dist/contracts/dist/events.js +1 -0
  8. package/dist/contracts/dist/experiments/evaluator.js +1 -0
  9. package/dist/contracts/dist/graphql-federation/dist/index.js +1 -0
  10. package/dist/contracts/dist/index.js +1 -0
  11. package/dist/contracts/dist/install.js +1 -0
  12. package/dist/contracts/dist/integrations/contracts.js +1 -0
  13. package/dist/contracts/dist/integrations/index.js +1 -0
  14. package/dist/contracts/dist/integrations/openbanking/contracts/accounts.js +1 -0
  15. package/dist/contracts/dist/integrations/openbanking/contracts/balances.js +1 -0
  16. package/dist/contracts/dist/integrations/openbanking/contracts/index.js +1 -0
  17. package/dist/contracts/dist/integrations/openbanking/contracts/transactions.js +1 -0
  18. package/dist/contracts/dist/integrations/openbanking/models.js +1 -0
  19. package/dist/contracts/dist/integrations/openbanking/telemetry.js +1 -0
  20. package/dist/contracts/dist/integrations/providers/elevenlabs.js +1 -0
  21. package/dist/contracts/dist/integrations/providers/gcs-storage.js +1 -0
  22. package/dist/contracts/dist/integrations/providers/gmail.js +1 -0
  23. package/dist/contracts/dist/integrations/providers/google-calendar.js +1 -0
  24. package/dist/contracts/dist/integrations/providers/impls/elevenlabs-voice.js +1 -0
  25. package/dist/contracts/dist/integrations/providers/impls/gcs-storage.js +1 -0
  26. package/dist/contracts/dist/integrations/providers/impls/gmail-inbound.js +1 -0
  27. package/dist/contracts/dist/integrations/providers/impls/gmail-outbound.js +1 -0
  28. package/dist/contracts/dist/integrations/providers/impls/google-calendar.js +1 -0
  29. package/dist/contracts/dist/integrations/providers/impls/index.js +1 -0
  30. package/dist/contracts/dist/integrations/providers/impls/mistral-embedding.js +1 -0
  31. package/dist/contracts/dist/integrations/providers/impls/mistral-llm.js +1 -0
  32. package/dist/contracts/dist/integrations/providers/impls/postmark-email.js +1 -0
  33. package/dist/contracts/dist/integrations/providers/impls/powens-client.js +1 -0
  34. package/dist/contracts/dist/integrations/providers/impls/powens-openbanking.js +1 -0
  35. package/dist/contracts/dist/integrations/providers/impls/provider-factory.js +1 -0
  36. package/dist/contracts/dist/integrations/providers/impls/qdrant-vector.js +1 -0
  37. package/dist/contracts/dist/integrations/providers/impls/stripe-payments.js +1 -0
  38. package/dist/contracts/dist/integrations/providers/impls/twilio-sms.js +1 -0
  39. package/dist/contracts/dist/integrations/providers/index.js +1 -0
  40. package/dist/contracts/dist/integrations/providers/mistral.js +1 -0
  41. package/dist/contracts/dist/integrations/providers/postmark.js +1 -0
  42. package/dist/contracts/dist/integrations/providers/powens.js +1 -0
  43. package/dist/contracts/dist/integrations/providers/qdrant.js +1 -0
  44. package/dist/contracts/dist/integrations/providers/stripe.js +1 -0
  45. package/dist/contracts/dist/integrations/providers/twilio-sms.js +1 -0
  46. package/dist/contracts/dist/integrations/runtime.js +1 -0
  47. package/dist/contracts/dist/integrations/secrets/env-secret-provider.js +1 -0
  48. package/dist/contracts/dist/integrations/secrets/gcp-secret-manager.js +1 -0
  49. package/dist/contracts/dist/integrations/secrets/index.js +1 -0
  50. package/dist/contracts/dist/integrations/secrets/manager.js +1 -0
  51. package/dist/contracts/dist/integrations/secrets/provider.js +1 -0
  52. package/dist/contracts/dist/jsonschema.js +1 -0
  53. package/dist/contracts/dist/knowledge/contracts.js +1 -0
  54. package/dist/contracts/dist/knowledge/index.js +1 -0
  55. package/dist/contracts/dist/knowledge/spaces/email-threads.js +1 -0
  56. package/dist/contracts/dist/knowledge/spaces/financial-docs.js +1 -0
  57. package/dist/contracts/dist/knowledge/spaces/financial-overview.js +1 -0
  58. package/dist/contracts/dist/knowledge/spaces/index.js +1 -0
  59. package/dist/contracts/dist/knowledge/spaces/product-canon.js +1 -0
  60. package/dist/contracts/dist/knowledge/spaces/support-faq.js +1 -0
  61. package/dist/contracts/dist/knowledge/spaces/uploaded-docs.js +1 -0
  62. package/dist/contracts/dist/onboarding-base.js +1 -0
  63. package/dist/contracts/dist/ownership.js +1 -0
  64. package/dist/contracts/dist/presentations.js +1 -0
  65. package/dist/contracts/dist/presentations.v2.js +1 -0
  66. package/dist/contracts/dist/prompt.js +1 -0
  67. package/dist/contracts/dist/promptRegistry.js +1 -0
  68. package/dist/contracts/dist/regenerator/index.js +1 -0
  69. package/dist/contracts/dist/regenerator/service.js +1 -0
  70. package/dist/contracts/dist/registry.js +1 -0
  71. package/dist/contracts/dist/resources.js +1 -0
  72. package/dist/contracts/dist/schema/dist/EnumType.js +1 -0
  73. package/dist/contracts/dist/schema/dist/FieldType.js +1 -0
  74. package/dist/contracts/dist/schema/dist/ScalarTypeEnum.js +1 -0
  75. package/dist/contracts/dist/schema/dist/SchemaModel.js +1 -0
  76. package/dist/contracts/dist/schema/dist/entity/defineEntity.js +1 -0
  77. package/dist/contracts/dist/schema/dist/entity/index.js +1 -0
  78. package/dist/contracts/dist/schema/dist/entity/types.js +1 -0
  79. package/dist/contracts/dist/schema/dist/index.js +1 -0
  80. package/dist/contracts/dist/server/graphql-pothos.js +1 -0
  81. package/dist/contracts/dist/server/graphql-schema-export.js +1 -0
  82. package/dist/contracts/dist/server/index.js +1 -0
  83. package/dist/contracts/dist/server/provider-mcp.js +1 -0
  84. package/dist/contracts/dist/server/rest-elysia.js +1 -0
  85. package/dist/contracts/dist/server/rest-express.js +1 -0
  86. package/dist/contracts/dist/server/rest-generic.js +1 -0
  87. package/dist/contracts/dist/server/rest-next-app.js +1 -0
  88. package/dist/contracts/dist/server/rest-next-pages.js +1 -0
  89. package/dist/contracts/dist/spec.js +1 -0
  90. package/dist/contracts/dist/telemetry/index.js +1 -0
  91. package/dist/contracts/dist/telemetry/tracker.js +1 -0
  92. package/dist/contracts/dist/tests/index.js +1 -0
  93. package/dist/contracts/dist/tests/runner.js +1 -0
  94. package/dist/contracts/dist/workflow/index.js +1 -0
  95. package/dist/contracts/dist/workflow/runner.js +1 -0
  96. package/dist/contracts/index.d.ts +1139 -0
  97. package/dist/contracts/index.js +1 -0
  98. package/dist/entities/index.d.ts +168 -0
  99. package/dist/entities/index.js +1 -0
  100. package/dist/events.d.ts +467 -0
  101. package/dist/events.js +1 -0
  102. package/dist/index.d.ts +5 -0
  103. package/dist/index.js +1 -0
  104. package/dist/schema/dist/EnumType.js +1 -0
  105. package/dist/schema/dist/FieldType.js +1 -0
  106. package/dist/schema/dist/ScalarTypeEnum.js +1 -0
  107. package/dist/schema/dist/SchemaModel.js +1 -0
  108. package/dist/schema/dist/entity/defineEntity.js +1 -0
  109. package/dist/schema/dist/entity/index.js +1 -0
  110. package/dist/schema/dist/entity/types.js +1 -0
  111. package/dist/schema/dist/index.js +1 -0
  112. package/dist/storage/index.d.ts +200 -0
  113. package/dist/storage/index.js +1 -0
  114. package/package.json +45 -0
@@ -0,0 +1,5 @@
1
+ import { AttachFileContract, AttachmentModel, CreatePresignedUrlContract, CreateVersionContract, DeleteFileContract, DetachFileContract, FileModel, FileVersionModel, GetDownloadUrlContract, GetFileContract, GetVersionsContract, ListAttachmentsContract, ListFilesContract, PresignedUrlModel, UpdateFileContract, UploadFileContract } from "./contracts/index.js";
2
+ import { AttachmentEntity, FileEntity, FileStatusEnum, FileVersionEntity, StorageProviderEnum, UploadSessionEntity, fileEntities, filesSchemaContribution } from "./entities/index.js";
3
+ import { AttachmentAttachedEvent, AttachmentDetachedEvent, FileDeletedEvent, FileEvents, FileUpdatedEvent, FileUploadedEvent, FileVersionCreatedEvent, UploadSessionCompletedEvent, UploadSessionStartedEvent } from "./events.js";
4
+ import { InMemoryStorageAdapter, ListOptions, ListResult, LocalStorageAdapter, LocalStorageOptions, PresignedDownloadOptions, PresignedUploadOptions, PresignedUrl, S3StorageAdapter, S3StorageOptions, StorageAdapter, StorageConfig, StorageFile, StorageProvider, UploadOptions, createStorageAdapter } from "./storage/index.js";
5
+ export { AttachFileContract, AttachmentAttachedEvent, AttachmentDetachedEvent, AttachmentEntity, AttachmentModel, CreatePresignedUrlContract, CreateVersionContract, DeleteFileContract, DetachFileContract, FileDeletedEvent, FileEntity, FileEvents, FileModel, FileStatusEnum, FileUpdatedEvent, FileUploadedEvent, FileVersionCreatedEvent, FileVersionEntity, FileVersionModel, GetDownloadUrlContract, GetFileContract, GetVersionsContract, InMemoryStorageAdapter, ListAttachmentsContract, ListFilesContract, ListOptions, ListResult, LocalStorageAdapter, LocalStorageOptions, PresignedDownloadOptions, PresignedUploadOptions, PresignedUrl, PresignedUrlModel, S3StorageAdapter, S3StorageOptions, StorageAdapter, StorageConfig, StorageFile, StorageProvider, StorageProviderEnum, UpdateFileContract, UploadFileContract, UploadOptions, UploadSessionCompletedEvent, UploadSessionEntity, UploadSessionStartedEvent, createStorageAdapter, fileEntities, filesSchemaContribution };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{AttachmentAttachedEvent as e,AttachmentDetachedEvent as t,FileDeletedEvent as n,FileEvents as r,FileUpdatedEvent as i,FileUploadedEvent as a,FileVersionCreatedEvent as o,UploadSessionCompletedEvent as s,UploadSessionStartedEvent as c}from"./events.js";import{AttachmentEntity as l,FileEntity as u,FileStatusEnum as d,FileVersionEntity as f,StorageProviderEnum as p,UploadSessionEntity as m,fileEntities as h,filesSchemaContribution as g}from"./entities/index.js";import{AttachFileContract as _,AttachmentModel as v,CreatePresignedUrlContract as y,CreateVersionContract as b,DeleteFileContract as x,DetachFileContract as S,FileModel as C,FileVersionModel as w,GetDownloadUrlContract as T,GetFileContract as E,GetVersionsContract as D,ListAttachmentsContract as O,ListFilesContract as k,PresignedUrlModel as A,UpdateFileContract as j,UploadFileContract as M}from"./contracts/index.js";import{InMemoryStorageAdapter as N,LocalStorageAdapter as P,S3StorageAdapter as F,createStorageAdapter as I}from"./storage/index.js";export{_ as AttachFileContract,e as AttachmentAttachedEvent,t as AttachmentDetachedEvent,l as AttachmentEntity,v as AttachmentModel,y as CreatePresignedUrlContract,b as CreateVersionContract,x as DeleteFileContract,S as DetachFileContract,n as FileDeletedEvent,u as FileEntity,r as FileEvents,C as FileModel,d as FileStatusEnum,i as FileUpdatedEvent,a as FileUploadedEvent,o as FileVersionCreatedEvent,f as FileVersionEntity,w as FileVersionModel,T as GetDownloadUrlContract,E as GetFileContract,D as GetVersionsContract,N as InMemoryStorageAdapter,O as ListAttachmentsContract,k as ListFilesContract,P as LocalStorageAdapter,A as PresignedUrlModel,F as S3StorageAdapter,p as StorageProviderEnum,j as UpdateFileContract,M as UploadFileContract,s as UploadSessionCompletedEvent,m as UploadSessionEntity,c as UploadSessionStartedEvent,I as createStorageAdapter,h as fileEntities,g as filesSchemaContribution};
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";import"graphql";
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";import{GraphQLScalarType as t}from"graphql";var n=class extends t{zodSchema;jsonSchemaDef;constructor(e){super(e),this.zodSchema=e.zod,this.jsonSchemaDef=e.jsonSchema}getZod(){return this.zodSchema}getPothos(){return this}getJson(){return typeof this.jsonSchemaDef==`function`?this.jsonSchemaDef():this.jsonSchemaDef}getJsonSchemaDef(){return this.jsonSchemaDef}getJsonSchema(){let e=t=>{let n=typeof t==`function`?t():t;if(Array.isArray(n))return n.map(t=>e(t));if(n&&typeof n==`object`){let t={};for(let[r,i]of Object.entries(n))t[r]=e(i);return t}return n};return e(this.getJson())}};export{n};
@@ -0,0 +1 @@
1
+ import{n as e}from"./FieldType.js";import{z as t}from"zod";import{Kind as n}from"graphql";const r=/^[A-Za-z]{2}(?:-[A-Za-z0-9]{2,8})*$/,i=/^(?:UTC|[A-Za-z_]+\/[A-Za-z_]+)$/,a=/^[+]?\d[\d\s().-]{3,}$/,o=/^[A-Z]{3}$/,s=/^[A-Z]{2}$/,c=-180,l={String_unsecure:()=>new e({name:`String_unsecure`,description:`Unvalidated string scalar`,zod:t.string(),parseValue:e=>t.string().parse(e),serialize:e=>String(e),parseLiteral:e=>{if(e.kind!==n.STRING)throw TypeError(`Invalid literal`);return e.value},jsonSchema:{type:`string`}}),Int_unsecure:()=>new e({name:`Int_unsecure`,description:`Unvalidated integer scalar`,zod:t.number().int(),parseValue:e=>{let n=typeof e==`number`?e:Number(e);return t.number().int().parse(n)},serialize:e=>Math.trunc(typeof e==`number`?e:Number(e)),parseLiteral:e=>{if(e.kind!==n.INT)throw TypeError(`Invalid literal`);return Number(e.value)},jsonSchema:{type:`integer`}}),Float_unsecure:()=>new e({name:`Float_unsecure`,description:`Unvalidated float scalar`,zod:t.number(),parseValue:e=>{let n=typeof e==`number`?e:Number(e);return t.number().parse(n)},serialize:e=>Number(e),parseLiteral:e=>{if(e.kind!==n.FLOAT&&e.kind!==n.INT)throw TypeError(`Invalid literal`);return Number(e.value)},jsonSchema:{type:`number`}}),Boolean:()=>new e({name:`Boolean`,description:`Unvalidated boolean scalar`,zod:t.boolean(),parseValue:e=>t.coerce.boolean().parse(e),serialize:e=>!!e,parseLiteral:e=>{if(e.kind!==n.BOOLEAN)throw TypeError(`Invalid literal`);return e.value},jsonSchema:{type:`boolean`}}),ID:()=>new e({name:`ID`,description:`Unvalidated id scalar`,zod:t.string(),parseValue:e=>t.string().parse(e),serialize:e=>String(e),parseLiteral:e=>{if(e.kind!==n.STRING)throw TypeError(`Invalid literal`);return e.value},jsonSchema:{type:`string`}}),JSON:()=>new e({name:`JSON`,zod:t.any(),parseValue:e=>e,serialize:e=>e,jsonSchema:{}}),JSONObject:()=>new e({name:`JSONObject`,zod:t.record(t.string(),t.any()),parseValue:e=>t.record(t.string(),t.any()).parse(e),serialize:e=>e??{},jsonSchema:{type:`object`}}),Date:()=>new e({name:`Date`,zod:t.date(),parseValue:e=>e instanceof Date?e:new Date(String(e)),serialize:e=>e instanceof Date?e.toISOString().split(`T`)[0]:String(e),jsonSchema:{type:`string`,format:`date`}}),DateTime:()=>new e({name:`DateTime`,zod:t.date(),parseValue:e=>e instanceof Date?e:new Date(String(e)),serialize:e=>e instanceof Date?e.toISOString():String(e),jsonSchema:{type:`string`,format:`date-time`}}),Time:()=>new e({name:`Time`,zod:t.string().regex(/^\d{2}:\d{2}(:\d{2})?$/),parseValue:e=>t.string().regex(/^\d{2}:\d{2}(:\d{2})?$/).parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,pattern:`^\\d{2}:\\d{2}(:\\d{2})?$`}}),EmailAddress:()=>new e({name:`EmailAddress`,zod:t.string().email(),parseValue:e=>t.string().email().parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,format:`email`}}),URL:()=>new e({name:`URL`,zod:t.string().url(),parseValue:e=>t.string().url().parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,format:`uri`}}),PhoneNumber:()=>new e({name:`PhoneNumber`,zod:t.string().regex(a),parseValue:e=>t.string().regex(a).parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,pattern:a.source}}),NonEmptyString:()=>new e({name:`NonEmptyString`,zod:t.string().min(1),parseValue:e=>t.string().min(1).parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,minLength:1}}),Locale:()=>new e({name:`Locale`,zod:t.string().regex(r),parseValue:e=>t.string().regex(r).parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,pattern:r.source}}),TimeZone:()=>new e({name:`TimeZone`,zod:t.string().regex(i),parseValue:e=>t.string().regex(i).parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,pattern:i.source}}),Latitude:()=>new e({name:`Latitude`,zod:t.number().min(-90).max(90),parseValue:e=>t.coerce.number().min(-90).max(90).parse(e),serialize:e=>Number(e),jsonSchema:{type:`number`,minimum:-90,maximum:90}}),Longitude:()=>new e({name:`Longitude`,zod:t.number().min(c).max(180),parseValue:e=>t.coerce.number().min(c).max(180).parse(e),serialize:e=>Number(e),jsonSchema:{type:`number`,minimum:c,maximum:180}}),Currency:()=>new e({name:`Currency`,zod:t.string().regex(o),parseValue:e=>t.string().regex(o).parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,pattern:o.source}}),CountryCode:()=>new e({name:`CountryCode`,zod:t.string().regex(s),parseValue:e=>t.string().regex(s).parse(e),serialize:e=>String(e),jsonSchema:{type:`string`,pattern:s.source}})};export{l};
@@ -0,0 +1 @@
1
+ import"./EnumType.js";import"./FieldType.js";import{z as e}from"zod";var t=class{constructor(e){this.config=e}getZod(){let t=Object.entries(this.config.fields).reduce((t,[n,r])=>{let i=r.type.getZod(),a=r.isArray?e.array(i):i;return t[n]=r.isOptional?a.optional():a,t},{});return e.object(t)}getPothosInput(){return this.config.name}};const n=e=>new t(e);export{n,t};
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";function t(e){return e}function n(e){return e}const r={string(e){return{kind:`scalar`,type:`String`,...e}},int(e){return{kind:`scalar`,type:`Int`,...e}},float(e){return{kind:`scalar`,type:`Float`,...e}},boolean(e){return{kind:`scalar`,type:`Boolean`,...e}},dateTime(e){return{kind:`scalar`,type:`DateTime`,...e}},json(e){return{kind:`scalar`,type:`Json`,...e}},bigInt(e){return{kind:`scalar`,type:`BigInt`,...e}},decimal(e){return{kind:`scalar`,type:`Decimal`,...e}},bytes(e){return{kind:`scalar`,type:`Bytes`,...e}},id(e){return{kind:`scalar`,type:`String`,isId:!0,default:`cuid()`,...e}},uuid(e){return{kind:`scalar`,type:`String`,isId:!0,default:`uuid()`,...e}},autoIncrement(e){return{kind:`scalar`,type:`Int`,isId:!0,default:`autoincrement()`,...e}},createdAt(e){return{kind:`scalar`,type:`DateTime`,default:`now()`,...e}},updatedAt(e){return{kind:`scalar`,type:`DateTime`,updatedAt:!0,...e}},email(t){return{kind:`scalar`,type:`String`,zod:e.email(),...t}},url(t){return{kind:`scalar`,type:`String`,zod:e.url(),...t}},enum(e,t){return{kind:`enum`,enumName:e,...t}},inlineEnum(e,t,n){return{kind:`enum`,enumName:e,values:t,...n}},hasOne(e,t){return{kind:`relation`,type:`hasOne`,target:e,...t}},hasMany(e,t){return{kind:`relation`,type:`hasMany`,target:e,...t}},belongsTo(e,t,n,r){return{kind:`relation`,type:`belongsTo`,target:e,fields:t,references:n,...r}},foreignKey(e){return{kind:`scalar`,type:`String`,...e}}},i={on(e,t){return{fields:e,...t}},unique(e,t){return{fields:e,unique:!0,...t}},compound(e,t,n){return{fields:e,sort:t,...n}}};export{i,n,r,t};
@@ -0,0 +1 @@
1
+ import{i as e,n as t,r as n,t as r}from"./defineEntity.js";import"./types.js";
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";
@@ -0,0 +1 @@
1
+ import"./EnumType.js";import{n as e}from"./FieldType.js";import{l as t}from"./ScalarTypeEnum.js";import{n,t as r}from"./SchemaModel.js";import{i,n as a,r as o,t as s}from"./entity/defineEntity.js";import"./entity/index.js";
@@ -0,0 +1,200 @@
1
+ //#region src/storage/index.d.ts
2
+ /**
3
+ * File storage adapters for different backends.
4
+ */
5
+ type StorageProvider = 'LOCAL' | 'S3' | 'GCS' | 'AZURE' | 'CLOUDFLARE';
6
+ interface StorageFile {
7
+ path: string;
8
+ size: number;
9
+ mimeType: string;
10
+ checksum?: string;
11
+ etag?: string;
12
+ metadata?: Record<string, string>;
13
+ }
14
+ interface UploadOptions {
15
+ /** Target path in storage */
16
+ path: string;
17
+ /** File content */
18
+ content: Buffer | string;
19
+ /** MIME type */
20
+ mimeType: string;
21
+ /** Additional metadata */
22
+ metadata?: Record<string, string>;
23
+ /** Whether file should be publicly accessible */
24
+ isPublic?: boolean;
25
+ }
26
+ interface PresignedUploadOptions {
27
+ /** Target path in storage */
28
+ path: string;
29
+ /** MIME type */
30
+ mimeType: string;
31
+ /** File size in bytes */
32
+ size: number;
33
+ /** Expiration time in seconds */
34
+ expiresIn?: number;
35
+ /** Additional conditions */
36
+ conditions?: Record<string, unknown>[];
37
+ }
38
+ interface PresignedDownloadOptions {
39
+ /** File path in storage */
40
+ path: string;
41
+ /** Expiration time in seconds */
42
+ expiresIn?: number;
43
+ /** Response content disposition */
44
+ contentDisposition?: string;
45
+ }
46
+ interface PresignedUrl {
47
+ url: string;
48
+ fields?: Record<string, string>;
49
+ expiresAt: Date;
50
+ }
51
+ interface ListOptions {
52
+ /** Path prefix */
53
+ prefix?: string;
54
+ /** Maximum results */
55
+ limit?: number;
56
+ /** Continuation token */
57
+ cursor?: string;
58
+ }
59
+ interface ListResult {
60
+ files: StorageFile[];
61
+ cursor?: string;
62
+ hasMore: boolean;
63
+ }
64
+ interface StorageAdapter {
65
+ /** Storage provider type */
66
+ readonly provider: StorageProvider;
67
+ /**
68
+ * Upload a file to storage.
69
+ */
70
+ upload(options: UploadOptions): Promise<StorageFile>;
71
+ /**
72
+ * Download a file from storage.
73
+ */
74
+ download(path: string): Promise<Buffer>;
75
+ /**
76
+ * Delete a file from storage.
77
+ */
78
+ delete(path: string): Promise<void>;
79
+ /**
80
+ * Check if a file exists.
81
+ */
82
+ exists(path: string): Promise<boolean>;
83
+ /**
84
+ * Get file metadata.
85
+ */
86
+ getMetadata(path: string): Promise<StorageFile | null>;
87
+ /**
88
+ * List files in a directory.
89
+ */
90
+ list(options?: ListOptions): Promise<ListResult>;
91
+ /**
92
+ * Generate a presigned URL for uploading.
93
+ */
94
+ createPresignedUpload(options: PresignedUploadOptions): Promise<PresignedUrl>;
95
+ /**
96
+ * Generate a presigned URL for downloading.
97
+ */
98
+ createPresignedDownload(options: PresignedDownloadOptions): Promise<PresignedUrl>;
99
+ /**
100
+ * Get public URL for a file (if applicable).
101
+ */
102
+ getPublicUrl(path: string): string | null;
103
+ /**
104
+ * Copy a file within storage.
105
+ */
106
+ copy(sourcePath: string, destinationPath: string): Promise<StorageFile>;
107
+ }
108
+ interface LocalStorageOptions {
109
+ /** Base directory for file storage */
110
+ basePath: string;
111
+ /** Base URL for serving files (optional) */
112
+ baseUrl?: string;
113
+ }
114
+ /**
115
+ * Local filesystem storage adapter.
116
+ * For development and testing purposes.
117
+ */
118
+ declare class LocalStorageAdapter implements StorageAdapter {
119
+ readonly provider: StorageProvider;
120
+ private basePath;
121
+ private baseUrl?;
122
+ constructor(options: LocalStorageOptions);
123
+ upload(options: UploadOptions): Promise<StorageFile>;
124
+ download(filePath: string): Promise<Buffer>;
125
+ delete(filePath: string): Promise<void>;
126
+ exists(filePath: string): Promise<boolean>;
127
+ getMetadata(filePath: string): Promise<StorageFile | null>;
128
+ list(options?: ListOptions): Promise<ListResult>;
129
+ createPresignedUpload(options: PresignedUploadOptions): Promise<PresignedUrl>;
130
+ createPresignedDownload(options: PresignedDownloadOptions): Promise<PresignedUrl>;
131
+ getPublicUrl(filePath: string): string | null;
132
+ copy(sourcePath: string, destinationPath: string): Promise<StorageFile>;
133
+ }
134
+ interface S3StorageOptions {
135
+ /** S3 bucket name */
136
+ bucket: string;
137
+ /** AWS region */
138
+ region: string;
139
+ /** AWS access key ID */
140
+ accessKeyId?: string;
141
+ /** AWS secret access key */
142
+ secretAccessKey?: string;
143
+ /** Endpoint URL (for S3-compatible services) */
144
+ endpoint?: string;
145
+ /** Force path style (for S3-compatible services) */
146
+ forcePathStyle?: boolean;
147
+ /** Default ACL for uploads */
148
+ defaultAcl?: 'private' | 'public-read';
149
+ }
150
+ /**
151
+ * S3 storage adapter interface.
152
+ * Implementation would use AWS SDK or compatible client.
153
+ *
154
+ * This is a placeholder that defines the interface.
155
+ * Actual implementation would require @aws-sdk/client-s3 dependency.
156
+ */
157
+ declare class S3StorageAdapter implements StorageAdapter {
158
+ readonly provider: StorageProvider;
159
+ private config;
160
+ constructor(options: S3StorageOptions);
161
+ upload(options: UploadOptions): Promise<StorageFile>;
162
+ download(filePath: string): Promise<Buffer>;
163
+ delete(filePath: string): Promise<void>;
164
+ exists(filePath: string): Promise<boolean>;
165
+ getMetadata(filePath: string): Promise<StorageFile | null>;
166
+ list(options?: ListOptions): Promise<ListResult>;
167
+ createPresignedUpload(options: PresignedUploadOptions): Promise<PresignedUrl>;
168
+ createPresignedDownload(options: PresignedDownloadOptions): Promise<PresignedUrl>;
169
+ getPublicUrl(filePath: string): string | null;
170
+ copy(sourcePath: string, destinationPath: string): Promise<StorageFile>;
171
+ }
172
+ /**
173
+ * In-memory storage adapter for testing.
174
+ */
175
+ declare class InMemoryStorageAdapter implements StorageAdapter {
176
+ readonly provider: StorageProvider;
177
+ private files;
178
+ upload(options: UploadOptions): Promise<StorageFile>;
179
+ download(filePath: string): Promise<Buffer>;
180
+ delete(filePath: string): Promise<void>;
181
+ exists(filePath: string): Promise<boolean>;
182
+ getMetadata(filePath: string): Promise<StorageFile | null>;
183
+ list(options?: ListOptions): Promise<ListResult>;
184
+ createPresignedUpload(options: PresignedUploadOptions): Promise<PresignedUrl>;
185
+ createPresignedDownload(options: PresignedDownloadOptions): Promise<PresignedUrl>;
186
+ getPublicUrl(filePath: string): string | null;
187
+ copy(sourcePath: string, destinationPath: string): Promise<StorageFile>;
188
+ clear(): void;
189
+ }
190
+ interface StorageConfig {
191
+ provider: StorageProvider;
192
+ local?: LocalStorageOptions;
193
+ s3?: S3StorageOptions;
194
+ }
195
+ /**
196
+ * Create a storage adapter based on configuration.
197
+ */
198
+ declare function createStorageAdapter(config: StorageConfig): StorageAdapter;
199
+ //#endregion
200
+ export { InMemoryStorageAdapter, ListOptions, ListResult, LocalStorageAdapter, LocalStorageOptions, PresignedDownloadOptions, PresignedUploadOptions, PresignedUrl, S3StorageAdapter, S3StorageOptions, StorageAdapter, StorageConfig, StorageFile, StorageProvider, UploadOptions, createStorageAdapter };
@@ -0,0 +1 @@
1
+ import*as e from"node:crypto";import*as t from"node:fs/promises";import*as n from"node:path";var r=class{provider=`LOCAL`;basePath;baseUrl;constructor(e){this.basePath=e.basePath,this.baseUrl=e.baseUrl}async upload(r){let i=n.join(this.basePath,r.path),a=n.dirname(i);await t.mkdir(a,{recursive:!0});let o=typeof r.content==`string`?Buffer.from(r.content,`base64`):r.content;await t.writeFile(i,o);let s=e.createHash(`sha256`).update(o).digest(`hex`);return{path:r.path,size:o.length,mimeType:r.mimeType,checksum:s,metadata:r.metadata}}async download(e){let r=n.join(this.basePath,e);return t.readFile(r)}async delete(e){let r=n.join(this.basePath,e);await t.unlink(r)}async exists(e){let r=n.join(this.basePath,e);try{return await t.access(r),!0}catch{return!1}}async getMetadata(e){let r=n.join(this.basePath,e);try{return{path:e,size:(await t.stat(r)).size,mimeType:`application/octet-stream`}}catch{return null}}async list(e){let r=e?.prefix?n.join(this.basePath,e.prefix):this.basePath;try{let i=await t.readdir(r,{withFileTypes:!0}),a=[];for(let o of i)if(o.isFile()){let i=e?.prefix?n.join(e.prefix,o.name):o.name,s=await t.stat(n.join(r,o.name));a.push({path:i,size:s.size,mimeType:`application/octet-stream`})}let o=e?.limit||a.length;return{files:a.slice(0,o),hasMore:a.length>o}}catch{return{files:[],hasMore:!1}}}async createPresignedUpload(e){let t=e.expiresIn||3600,n=new Date(Date.now()+t*1e3);return{url:this.baseUrl?`${this.baseUrl}/upload?path=${encodeURIComponent(e.path)}`:`/upload?path=${encodeURIComponent(e.path)}`,fields:{path:e.path,mimeType:e.mimeType},expiresAt:n}}async createPresignedDownload(e){let t=e.expiresIn||3600,n=new Date(Date.now()+t*1e3);return{url:this.baseUrl?`${this.baseUrl}/download/${e.path}`:`/download/${e.path}`,expiresAt:n}}getPublicUrl(e){return this.baseUrl?`${this.baseUrl}/${e}`:null}async copy(e,r){let i=n.join(this.basePath,e),a=n.join(this.basePath,r),o=n.dirname(a);return await t.mkdir(o,{recursive:!0}),await t.copyFile(i,a),{path:r,size:(await t.stat(a)).size,mimeType:`application/octet-stream`}}},i=class{provider=`S3`;config;constructor(e){this.config=e}async upload(e){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the upload method.`)}async download(e){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the download method.`)}async delete(e){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the delete method.`)}async exists(e){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the exists method.`)}async getMetadata(e){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the getMetadata method.`)}async list(e){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the list method.`)}async createPresignedUpload(e){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the createPresignedUpload method.`)}async createPresignedDownload(e){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the createPresignedDownload method.`)}getPublicUrl(e){let{bucket:t,region:n,endpoint:r}=this.config;return r?`${r}/${t}/${e}`:`https://${t}.s3.${n}.amazonaws.com/${e}`}async copy(e,t){throw Error(`S3 adapter requires @aws-sdk/client-s3. Install it and implement the copy method.`)}},a=class{provider=`LOCAL`;files=new Map;async upload(t){let n=typeof t.content==`string`?Buffer.from(t.content,`base64`):t.content,r=e.createHash(`sha256`).update(n).digest(`hex`),i={path:t.path,size:n.length,mimeType:t.mimeType,checksum:r,metadata:t.metadata};return this.files.set(t.path,{content:n,metadata:i}),i}async download(e){let t=this.files.get(e);if(!t)throw Error(`File not found: ${e}`);return t.content}async delete(e){this.files.delete(e)}async exists(e){return this.files.has(e)}async getMetadata(e){return this.files.get(e)?.metadata||null}async list(e){let t=e?.prefix||``,n=[];for(let[e,r]of this.files)e.startsWith(t)&&n.push(r.metadata);let r=e?.limit||n.length;return{files:n.slice(0,r),hasMore:n.length>r}}async createPresignedUpload(e){let t=new Date(Date.now()+(e.expiresIn||3600)*1e3);return{url:`/upload?path=${encodeURIComponent(e.path)}`,fields:{path:e.path},expiresAt:t}}async createPresignedDownload(e){let t=new Date(Date.now()+(e.expiresIn||3600)*1e3);return{url:`/download/${e.path}`,expiresAt:t}}getPublicUrl(e){return`/files/${e}`}async copy(e,t){let n=this.files.get(e);if(!n)throw Error(`Source file not found: ${e}`);let r={...n.metadata,path:t};return this.files.set(t,{content:n.content,metadata:r}),r}clear(){this.files.clear()}};function o(e){switch(e.provider){case`LOCAL`:if(!e.local)throw Error(`Local storage configuration required`);return new r(e.local);case`S3`:if(!e.s3)throw Error(`S3 storage configuration required`);return new i(e.s3);default:throw Error(`Unsupported storage provider: ${e.provider}`)}}export{a as InMemoryStorageAdapter,r as LocalStorageAdapter,i as S3StorageAdapter,o as createStorageAdapter};
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@lssm/lib.files",
3
+ "version": "0.0.0-canary-20251206160926",
4
+ "description": "Files, documents and attachments module for ContractSpec applications",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
10
+ "build": "bun build:bundle && bun build:types",
11
+ "build:bundle": "tsdown",
12
+ "build:types": "tsc --noEmit",
13
+ "dev": "bun build:bundle --watch",
14
+ "clean": "rimraf dist .turbo",
15
+ "lint": "bun lint:fix",
16
+ "lint:fix": "eslint src --fix",
17
+ "lint:check": "eslint src"
18
+ },
19
+ "dependencies": {
20
+ "@lssm/lib.schema": "workspace:*",
21
+ "@lssm/lib.contracts": "workspace:*",
22
+ "zod": "^4.1.13"
23
+ },
24
+ "devDependencies": {
25
+ "@lssm/tool.typescript": "workspace:*",
26
+ "@lssm/tool.tsdown": "workspace:*",
27
+ "typescript": "^5.9.3"
28
+ },
29
+ "exports": {
30
+ ".": "./dist/index.js",
31
+ "./contracts": "./dist/contracts/index.js",
32
+ "./entities": "./dist/entities/index.js",
33
+ "./events": "./dist/events.js",
34
+ "./storage": "./dist/storage/index.js",
35
+ "./*": "./*"
36
+ },
37
+ "module": "./dist/index.js",
38
+ "files": [
39
+ "dist",
40
+ "README.md"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }