@m1cro/server-sdk 0.1.0 → 0.1.1-beta.11

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/globals.d.ts CHANGED
@@ -1,13 +1,10 @@
1
+ import { B as Bridge, L as LogLevel } from './log-DvhHJYGt.js';
1
2
  import * as console from 'node:console';
2
-
3
- declare const logLevels: readonly ["trace", "debug", "info", "warn", "error", "none"];
4
- type LogLevel = (typeof logLevels)[number];
3
+ import 'cookie';
5
4
 
6
5
  declare global {
6
+ var Bridge: Bridge;
7
7
  interface Console extends console.Console {
8
8
  logLevel: LogLevel;
9
9
  }
10
- interface Request {
11
- artifacts?: any;
12
- }
13
10
  }
package/dist/globals.js CHANGED
@@ -1,2 +0,0 @@
1
- //# sourceMappingURL=globals.js.map
2
- //# sourceMappingURL=globals.js.map
package/dist/index.d.ts CHANGED
@@ -1,273 +1,249 @@
1
- import { JSONSchema4 } from 'json-schema';
1
+ import { R as Router, H as HookEventMap, A as AppRole, E as EventHandler } from './log-DvhHJYGt.js';
2
+ export { a as AppId, b as Artifacts, c as Auth, B as Bridge, d as Entity, L as LogLevel, M as Method, e as Middleware, N as Namespace, P as Provider, f as Providers, g as Request, h as RequestBuilder, i as RequestHandler, j as Response, k as ResponseBuilder, l as RouteOptions, S as StatusCode, m as Subject, T as Tenant, V as Visibility } from './log-DvhHJYGt.js';
3
+ import 'cookie';
2
4
 
3
- interface Crypto {
4
- deriveKey(seed: string, length: number): Uint8Array;
5
- aesGcmEncrypt<T>(data: T): Uint8Array;
6
- aesGcmDecrypt<T>(data: Uint8Array): T;
7
- argon2Hash(algorithm: Argon2Algorithm, password: string, options?: Argon2Options): string;
8
- argon2Verify(algorithm: Argon2Algorithm, password: string, hash: string, options?: Argon2Options): boolean;
9
- }
10
- type Argon2Algorithm = 'argon2d' | 'argon2i' | 'argon2id';
11
- interface Argon2Options {
12
- mCost?: number;
13
- tCost?: number;
14
- pCost?: number;
15
- outputLen?: number;
5
+ interface EntityModelRegistration {
6
+ get name(): string;
7
+ get schema(): {
8
+ get shape(): unknown;
9
+ };
16
10
  }
17
11
 
18
- type Record<K extends string | number | symbol = string, V = any> = {
19
- [key in K]: V;
20
- };
21
- type Variant<K extends PropertyKey, T extends object> = {
22
- [P in keyof T]: ({
23
- [Q in K]: P;
24
- } & T[P]) extends infer U ? {
25
- [Q in keyof U]: U[Q];
26
- } : never;
27
- }[keyof T];
28
- type EventHandler = <T>(this: App, event: string, data: T) => void | Promise<void>;
29
- type Visibility = 'private' | 'platform' | 'vendor' | 'public';
30
- interface Tenant {
31
- id: string;
32
- host: string;
33
- }
34
- interface AppId {
35
- namespace: string;
36
- app: string;
37
- }
38
- type AppRole = Variant<"type", AppRoleData>;
39
- type AppRoleData = {
40
- provider: {
41
- group: string;
42
- };
43
- test: void;
12
+ type EntryPoint = (app: App) => unknown;
13
+ interface App {
14
+ get router(): Router;
15
+ on<K extends keyof HookEventMap>(type: K, listener: (...args: HookEventMap[K]) => unknown): App;
16
+ role(role: AppRole): App;
17
+ capability(app: string, permissions: string[]): App;
18
+ capabilities(capabilities: {
19
+ [app: string]: string[];
20
+ }): App;
21
+ entity(model: EntityModelRegistration): App;
22
+ subscribe(pattern: string, handler: EventHandler): App;
23
+ }
24
+
25
+ declare const _default: {
26
+ encode<T>(data: T): Uint8Array;
27
+ decode<T>(data: Uint8Array): T;
44
28
  };
45
- interface Auth {
46
- subject: Subject;
47
- permissions: Permissions;
29
+
30
+ interface ErrorPayload {
31
+ status: number;
32
+ code: string;
33
+ msg?: string | undefined;
48
34
  }
49
- interface Subject {
50
- id: string;
51
- email: string;
52
- roles: string[];
35
+ declare class Base extends Error {
36
+ protected payload: ErrorPayload;
37
+ constructor(payload: ErrorPayload);
38
+ status(status: number): this;
39
+ code(code: string): this;
40
+ msg(msg: string): this;
53
41
  }
54
- interface Permissions {
55
- [key: string]: string[];
42
+ declare class BadRequest extends Base {
43
+ constructor(msg?: string);
56
44
  }
57
- interface HookEventMap {
58
- "start": [];
59
- "install": [];
45
+ declare class Unauthorized extends Base {
46
+ constructor(msg?: string);
60
47
  }
61
-
62
- interface FindQuery<T extends Record = Record> {
63
- limit(limit: number): this;
64
- offset(offset: number): this;
65
- sort(sort: Sorting): this;
66
- exec(): Promise<T[]>;
48
+ declare class PaymentRequired extends Base {
49
+ constructor(msg?: string);
67
50
  }
68
- interface FindOneQuery<T extends Record = Record> {
69
- offset(offset: number): this;
70
- sort(sort: Sorting): this;
71
- exec(): Promise<T | undefined>;
51
+ declare class Forbidden extends Base {
52
+ constructor(msg?: string);
72
53
  }
73
-
74
- type InsertReturnMode = 'insertedIds' | 'documents';
75
- type InsertReturnType<T extends Record, R extends InsertReturnMode> = R extends 'insertedIds' ? string[] : R extends 'documents' ? T[] : never;
76
- interface InsertQuery<T extends Record = Record, R extends InsertReturnMode = 'insertedIds'> {
77
- return(mode: 'insertedIds'): InsertQuery<T, 'insertedIds'>;
78
- return(mode: 'documents'): InsertQuery<T, 'documents'>;
79
- return(mode: InsertReturnMode): InsertQuery<T, typeof mode>;
80
- exec(): Promise<InsertReturnType<T, R>>;
81
- }
82
- type InsertOneReturnMode = 'insertedId' | 'document';
83
- type InsertOneReturnType<T extends Record, R extends InsertOneReturnMode> = R extends 'insertedId' ? string : R extends 'document' ? T : never;
84
- interface InsertOneQuery<T extends Record = Record, R extends InsertOneReturnMode = 'insertedId'> {
85
- return(mode: 'insertedId'): InsertOneQuery<T, 'insertedId'>;
86
- return(mode: 'document'): InsertOneQuery<T, 'document'>;
87
- return(mode: InsertOneReturnMode): InsertOneQuery<T, typeof mode>;
88
- exec(): Promise<InsertOneReturnType<T, R>>;
54
+ declare class NotFound extends Base {
55
+ constructor(msg?: string);
89
56
  }
90
-
91
- type UpdateReturnMode = 'affectedRows' | 'oldDocuments' | 'newDocuments';
92
- type UpdateReturnType<T, R extends UpdateReturnMode> = R extends 'affectedRows' ? bigint : R extends 'oldDocuments' | 'newDocuments' ? T[] : never;
93
- interface UpdateQuery<T extends Record = Record, R extends UpdateReturnMode = 'affectedRows'> {
94
- limit(limit: number): this;
95
- offset(offset: number): this;
96
- sort(sort: Sorting): this;
97
- return(mode: 'affectedRows'): UpdateQuery<T, 'affectedRows'>;
98
- return(mode: 'oldDocuments'): UpdateQuery<T, 'oldDocuments'>;
99
- return(mode: 'newDocuments'): UpdateQuery<T, 'newDocuments'>;
100
- return(mode: UpdateReturnMode): UpdateQuery<T, typeof mode>;
101
- exec(): Promise<UpdateReturnType<T, R>>;
102
- }
103
- type UpdateOneReturnMode = 'success' | 'oldDocument' | 'newDocument';
104
- type UpdateOneReturnType<T, R extends UpdateOneReturnMode> = R extends 'success' ? boolean : R extends 'oldDocument' | 'newDocument' ? (T | undefined) : never;
105
- interface UpdateOneQuery<T extends Record = Record, R extends UpdateOneReturnMode = 'success'> {
106
- offset(offset: number): this;
107
- sort(sort: Sorting): this;
108
- return(mode: 'success'): UpdateOneQuery<T, 'success'>;
109
- return(mode: 'oldDocument'): UpdateOneQuery<T, 'oldDocument'>;
110
- return(mode: 'newDocument'): UpdateOneQuery<T, 'newDocument'>;
111
- return(mode: UpdateOneReturnMode): UpdateOneQuery<T, typeof mode>;
112
- exec(): Promise<UpdateOneReturnType<T, R>>;
57
+ declare class MethodNotAllowed extends Base {
58
+ constructor(msg?: string);
113
59
  }
114
-
115
- type RemoveReturnMode = 'affectedRows' | 'documents';
116
- type RemoveReturnType<T, R extends RemoveReturnMode> = R extends 'affectedRows' ? bigint : R extends 'documents' ? T[] : never;
117
- interface RemoveQuery<T extends Record = Record, R extends RemoveReturnMode = 'affectedRows'> {
118
- limit(limit: number): this;
119
- offset(offset: number): this;
120
- sort(sort: Sorting): this;
121
- return(mode: 'affectedRows'): RemoveQuery<T, 'affectedRows'>;
122
- return(mode: 'documents'): RemoveQuery<T, 'documents'>;
123
- return(mode: RemoveReturnMode): RemoveQuery<T, typeof mode>;
124
- exec(): Promise<RemoveReturnType<T, R>>;
125
- }
126
- type RemoveOneReturnMode = 'success' | 'document';
127
- type RemoveOneReturnType<T, R extends RemoveOneReturnMode> = R extends 'success' ? boolean : R extends 'document' ? (T | undefined) : never;
128
- interface RemoveOneQuery<T extends Record = Record, R extends RemoveOneReturnMode = 'success'> {
129
- offset(offset: number): this;
130
- sort(sort: Sorting): this;
131
- return(mode: 'success'): RemoveOneQuery<T, 'success'>;
132
- return(mode: 'document'): RemoveOneQuery<T, 'document'>;
133
- return(mode: RemoveOneReturnMode): RemoveOneQuery<T, typeof mode>;
134
- exec(): Promise<RemoveOneReturnType<T, R>>;
60
+ declare class NotAcceptable extends Base {
61
+ constructor(msg?: string);
135
62
  }
136
-
137
- interface Entity<T extends object = Record<string, unknown>> {
138
- get name(): string;
139
- find(query: Record): FindQuery<T>;
140
- findOne(query: Record): FindOneQuery<T>;
141
- insert(docs: T[]): InsertQuery<T>;
142
- insertOne(doc: T): InsertOneQuery<T>;
143
- update(query: Record, update: Record): UpdateQuery<T>;
144
- updateOne(query: Record, update: Record): UpdateOneQuery<T>;
145
- remove(query: Record): RemoveQuery<T>;
146
- removeOne(query: Record): RemoveOneQuery<T>;
147
- }
148
- interface Sorting {
149
- [field: string]: 'asc' | 'desc';
63
+ declare class ProxyAuthenticationRequired extends Base {
64
+ constructor(msg?: string);
150
65
  }
151
-
152
- interface SetOptions {
153
- ttl?: number;
154
- existenceCheck?: "nx" | "xx";
66
+ declare class RequestTimeout extends Base {
67
+ constructor(msg?: string);
155
68
  }
156
- interface KeyValueStore {
157
- get<T>(key: string): Promise<T>;
158
- getDel<T>(key: string): Promise<T>;
159
- set<T>(key: string, value: T, options?: SetOptions): Promise<void>;
160
- delete(key: string): Promise<void>;
69
+ declare class Conflict extends Base {
70
+ constructor(msg?: string);
161
71
  }
162
-
163
- interface Providers {
164
- list(group: string): Provider[];
72
+ declare class Gone extends Base {
73
+ constructor(msg?: string);
165
74
  }
166
- interface Provider {
167
- group: string;
168
- app: AppId;
75
+ declare class LengthRequired extends Base {
76
+ constructor(msg?: string);
169
77
  }
170
-
171
- interface Artifacts {
172
- get<T>(key: string): T | undefined;
173
- set<T>(key: string, value: T): void;
174
- delete(key: string): void;
78
+ declare class PreconditionFailed extends Base {
79
+ constructor(msg?: string);
175
80
  }
176
-
177
- interface Router {
178
- scope(path: string): Router;
179
- route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;
180
- get(path: string, handler: RequestHandler, options?: RouteOptions): Router;
181
- post(path: string, handler: RequestHandler, options?: RouteOptions): Router;
182
- put(path: string, handler: RequestHandler, options?: RouteOptions): Router;
183
- patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;
184
- delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;
185
- }
186
- interface RouteOptions {
187
- timeoutMs?: number;
188
- permissions?: string[];
189
- authenticated?: boolean;
190
- visibility?: Visibility;
191
- }
192
- type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
193
- type RequestHandler = (this: App, req: Request, res: Response) => void | Promise<void>;
194
- interface Request {
195
- get artifacts(): Artifacts;
196
- get method(): Method;
197
- withMethod(method: Method): Request;
198
- get url(): URL;
199
- withUrl(url: string | URL): Request;
200
- header(name: string): string | undefined;
201
- withHeader(name: string, value: string): Request;
202
- get headers(): Headers;
203
- withHeaders(headers: HeadersInit): Request;
204
- body(): Promise<Uint8Array>;
205
- withBody(bytes: Uint8Array): Request;
206
- text(): Promise<string>;
207
- withText(text: string): Request;
208
- json<T>(): Promise<T>;
209
- withJson<T>(json: T): Request;
210
- }
211
- interface Response {
212
- get status(): number;
213
- withStatus(status: number): Response;
214
- header(name: string): string | undefined;
215
- withHeader(name: string, value: string): Response;
216
- get headers(): Headers;
217
- withHeaders(headers: HeadersInit): Response;
218
- body(): Promise<Uint8Array>;
219
- withBody(bytes: Uint8Array): Response;
220
- text(): Promise<string>;
221
- withText(text: string): Response;
222
- json<T>(): Promise<T>;
223
- withJson<T>(json: T): Response;
81
+ declare class ContentTooLarge extends Base {
82
+ constructor(msg?: string);
224
83
  }
225
-
226
- interface RPC {
227
- call(url: string, method: Method): Call;
228
- get(url: string): Call;
229
- post(url: string): Call;
230
- put(url: string): Call;
231
- patch(url: string): Call;
232
- delete(url: string): Call;
84
+ declare class URITooLong extends Base {
85
+ constructor(msg?: string);
233
86
  }
234
- interface Call extends Request {
235
- send(): Promise<Response>;
87
+ declare class UnsupportedMediaType extends Base {
88
+ constructor(msg?: string);
236
89
  }
237
-
238
- interface SSE {
239
- push<T>(event: T, targets: string[]): Promise<void>;
90
+ declare class RangeNotSatisfiable extends Base {
91
+ constructor(msg?: string);
240
92
  }
241
-
242
- interface App {
243
- get tenant(): Tenant;
244
- get providers(): Providers;
245
- settings<T>(): T | undefined;
246
- crd<T>(key: string): T | undefined;
247
- get rpc(): RPC;
248
- get kv(): KeyValueStore;
249
- get sse(): SSE;
250
- get crypto(): Crypto;
251
- entity<T extends object>(name: string): Entity<T>;
252
- publish<T extends object>(event: string, payload: T, visibility?: Visibility[]): void;
93
+ declare class ExpectationFailed extends Base {
94
+ constructor(msg?: string);
253
95
  }
254
-
255
- declare const _default: {
256
- encode<T>(data: T): Uint8Array;
257
- decode<T>(data: Uint8Array): T;
258
- };
259
-
260
- type EntryPoint = (builder: AppBuilder) => unknown;
261
- interface AppBuilder {
262
- on<K extends keyof HookEventMap>(type: K, listener: (this: App, ...args: HookEventMap[K]) => unknown): AppBuilder;
263
- role(role: AppRole): AppBuilder;
264
- capability(app: string, permissions: string[]): AppBuilder;
265
- capabilities(capabilities: {
266
- [app: string]: string[];
267
- }): AppBuilder;
268
- routes(factory: (router: Router) => unknown): AppBuilder;
269
- entity(name: string, schema: JSONSchema4): AppBuilder;
270
- subscribe(pattern: string, handler: EventHandler): AppBuilder;
96
+ declare class ImATeapot extends Base {
97
+ constructor(msg?: string);
271
98
  }
272
-
273
- export { type App, type AppBuilder, type AppId, type AppRole, type Artifacts, type Auth, type Entity, type EntryPoint, type Providers, type Request, type RequestHandler, type Response, type RouteOptions, type Router, type Tenant, _default as cbor };
99
+ declare class MisdirectedRequest extends Base {
100
+ constructor(msg?: string);
101
+ }
102
+ declare class UnprocessableEntity extends Base {
103
+ constructor(msg?: string);
104
+ }
105
+ declare class Locked extends Base {
106
+ constructor(msg?: string);
107
+ }
108
+ declare class FailedDependency extends Base {
109
+ constructor(msg?: string);
110
+ }
111
+ declare class TooEarly extends Base {
112
+ constructor(msg?: string);
113
+ }
114
+ declare class UpgradeRequired extends Base {
115
+ constructor(msg?: string);
116
+ }
117
+ declare class PreconditionRequired extends Base {
118
+ constructor(msg?: string);
119
+ }
120
+ declare class TooManyRequests extends Base {
121
+ constructor(msg?: string);
122
+ }
123
+ declare class RequestHeaderFieldsTooLarge extends Base {
124
+ constructor(msg?: string);
125
+ }
126
+ declare class UnavailableForLegalReasons extends Base {
127
+ constructor(msg?: string);
128
+ }
129
+ declare class InternalServerError extends Base {
130
+ constructor(msg?: string);
131
+ }
132
+ declare class NotImplemented extends Base {
133
+ constructor(msg?: string);
134
+ }
135
+ declare class BadGateway extends Base {
136
+ constructor(msg?: string);
137
+ }
138
+ declare class ServiceUnavailable extends Base {
139
+ constructor(msg?: string);
140
+ }
141
+ declare class GatewayTimeout extends Base {
142
+ constructor(msg?: string);
143
+ }
144
+ declare class HTTPVersionNotSupported extends Base {
145
+ constructor(msg?: string);
146
+ }
147
+ declare class VariantAlsoNegotiates extends Base {
148
+ constructor(msg?: string);
149
+ }
150
+ declare class InsufficientStorage extends Base {
151
+ constructor(msg?: string);
152
+ }
153
+ declare class LoopDetected extends Base {
154
+ constructor(msg?: string);
155
+ }
156
+ declare class NotExtended extends Base {
157
+ constructor(msg?: string);
158
+ }
159
+ declare class NetworkAuthenticationRequired extends Base {
160
+ constructor(msg?: string);
161
+ }
162
+
163
+ type error_BadGateway = BadGateway;
164
+ declare const error_BadGateway: typeof BadGateway;
165
+ type error_BadRequest = BadRequest;
166
+ declare const error_BadRequest: typeof BadRequest;
167
+ type error_Base = Base;
168
+ declare const error_Base: typeof Base;
169
+ type error_Conflict = Conflict;
170
+ declare const error_Conflict: typeof Conflict;
171
+ type error_ContentTooLarge = ContentTooLarge;
172
+ declare const error_ContentTooLarge: typeof ContentTooLarge;
173
+ type error_ExpectationFailed = ExpectationFailed;
174
+ declare const error_ExpectationFailed: typeof ExpectationFailed;
175
+ type error_FailedDependency = FailedDependency;
176
+ declare const error_FailedDependency: typeof FailedDependency;
177
+ type error_Forbidden = Forbidden;
178
+ declare const error_Forbidden: typeof Forbidden;
179
+ type error_GatewayTimeout = GatewayTimeout;
180
+ declare const error_GatewayTimeout: typeof GatewayTimeout;
181
+ type error_Gone = Gone;
182
+ declare const error_Gone: typeof Gone;
183
+ type error_HTTPVersionNotSupported = HTTPVersionNotSupported;
184
+ declare const error_HTTPVersionNotSupported: typeof HTTPVersionNotSupported;
185
+ type error_ImATeapot = ImATeapot;
186
+ declare const error_ImATeapot: typeof ImATeapot;
187
+ type error_InsufficientStorage = InsufficientStorage;
188
+ declare const error_InsufficientStorage: typeof InsufficientStorage;
189
+ type error_InternalServerError = InternalServerError;
190
+ declare const error_InternalServerError: typeof InternalServerError;
191
+ type error_LengthRequired = LengthRequired;
192
+ declare const error_LengthRequired: typeof LengthRequired;
193
+ type error_Locked = Locked;
194
+ declare const error_Locked: typeof Locked;
195
+ type error_LoopDetected = LoopDetected;
196
+ declare const error_LoopDetected: typeof LoopDetected;
197
+ type error_MethodNotAllowed = MethodNotAllowed;
198
+ declare const error_MethodNotAllowed: typeof MethodNotAllowed;
199
+ type error_MisdirectedRequest = MisdirectedRequest;
200
+ declare const error_MisdirectedRequest: typeof MisdirectedRequest;
201
+ type error_NetworkAuthenticationRequired = NetworkAuthenticationRequired;
202
+ declare const error_NetworkAuthenticationRequired: typeof NetworkAuthenticationRequired;
203
+ type error_NotAcceptable = NotAcceptable;
204
+ declare const error_NotAcceptable: typeof NotAcceptable;
205
+ type error_NotExtended = NotExtended;
206
+ declare const error_NotExtended: typeof NotExtended;
207
+ type error_NotFound = NotFound;
208
+ declare const error_NotFound: typeof NotFound;
209
+ type error_NotImplemented = NotImplemented;
210
+ declare const error_NotImplemented: typeof NotImplemented;
211
+ type error_PaymentRequired = PaymentRequired;
212
+ declare const error_PaymentRequired: typeof PaymentRequired;
213
+ type error_PreconditionFailed = PreconditionFailed;
214
+ declare const error_PreconditionFailed: typeof PreconditionFailed;
215
+ type error_PreconditionRequired = PreconditionRequired;
216
+ declare const error_PreconditionRequired: typeof PreconditionRequired;
217
+ type error_ProxyAuthenticationRequired = ProxyAuthenticationRequired;
218
+ declare const error_ProxyAuthenticationRequired: typeof ProxyAuthenticationRequired;
219
+ type error_RangeNotSatisfiable = RangeNotSatisfiable;
220
+ declare const error_RangeNotSatisfiable: typeof RangeNotSatisfiable;
221
+ type error_RequestHeaderFieldsTooLarge = RequestHeaderFieldsTooLarge;
222
+ declare const error_RequestHeaderFieldsTooLarge: typeof RequestHeaderFieldsTooLarge;
223
+ type error_RequestTimeout = RequestTimeout;
224
+ declare const error_RequestTimeout: typeof RequestTimeout;
225
+ type error_ServiceUnavailable = ServiceUnavailable;
226
+ declare const error_ServiceUnavailable: typeof ServiceUnavailable;
227
+ type error_TooEarly = TooEarly;
228
+ declare const error_TooEarly: typeof TooEarly;
229
+ type error_TooManyRequests = TooManyRequests;
230
+ declare const error_TooManyRequests: typeof TooManyRequests;
231
+ type error_URITooLong = URITooLong;
232
+ declare const error_URITooLong: typeof URITooLong;
233
+ type error_Unauthorized = Unauthorized;
234
+ declare const error_Unauthorized: typeof Unauthorized;
235
+ type error_UnavailableForLegalReasons = UnavailableForLegalReasons;
236
+ declare const error_UnavailableForLegalReasons: typeof UnavailableForLegalReasons;
237
+ type error_UnprocessableEntity = UnprocessableEntity;
238
+ declare const error_UnprocessableEntity: typeof UnprocessableEntity;
239
+ type error_UnsupportedMediaType = UnsupportedMediaType;
240
+ declare const error_UnsupportedMediaType: typeof UnsupportedMediaType;
241
+ type error_UpgradeRequired = UpgradeRequired;
242
+ declare const error_UpgradeRequired: typeof UpgradeRequired;
243
+ type error_VariantAlsoNegotiates = VariantAlsoNegotiates;
244
+ declare const error_VariantAlsoNegotiates: typeof VariantAlsoNegotiates;
245
+ declare namespace error {
246
+ export { error_BadGateway as BadGateway, error_BadRequest as BadRequest, error_Base as Base, error_Conflict as Conflict, error_ContentTooLarge as ContentTooLarge, error_ExpectationFailed as ExpectationFailed, error_FailedDependency as FailedDependency, error_Forbidden as Forbidden, error_GatewayTimeout as GatewayTimeout, error_Gone as Gone, error_HTTPVersionNotSupported as HTTPVersionNotSupported, error_ImATeapot as ImATeapot, error_InsufficientStorage as InsufficientStorage, error_InternalServerError as InternalServerError, error_LengthRequired as LengthRequired, error_Locked as Locked, error_LoopDetected as LoopDetected, error_MethodNotAllowed as MethodNotAllowed, error_MisdirectedRequest as MisdirectedRequest, error_NetworkAuthenticationRequired as NetworkAuthenticationRequired, error_NotAcceptable as NotAcceptable, error_NotExtended as NotExtended, error_NotFound as NotFound, error_NotImplemented as NotImplemented, error_PaymentRequired as PaymentRequired, error_PreconditionFailed as PreconditionFailed, error_PreconditionRequired as PreconditionRequired, error_ProxyAuthenticationRequired as ProxyAuthenticationRequired, error_RangeNotSatisfiable as RangeNotSatisfiable, error_RequestHeaderFieldsTooLarge as RequestHeaderFieldsTooLarge, error_RequestTimeout as RequestTimeout, error_ServiceUnavailable as ServiceUnavailable, error_TooEarly as TooEarly, error_TooManyRequests as TooManyRequests, error_URITooLong as URITooLong, error_Unauthorized as Unauthorized, error_UnavailableForLegalReasons as UnavailableForLegalReasons, error_UnprocessableEntity as UnprocessableEntity, error_UnsupportedMediaType as UnsupportedMediaType, error_UpgradeRequired as UpgradeRequired, error_VariantAlsoNegotiates as VariantAlsoNegotiates };
247
+ }
248
+
249
+ export { type App, AppRole, type EntryPoint, EventHandler, Router, _default as cbor, error };
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- import*as e from'cbor2';var t={encode(p){return e.encode(p)},decode(p){return e.decode(p)}};export{t as cbor};//# sourceMappingURL=index.js.map
2
- //# sourceMappingURL=index.js.map
1
+ import*as o from'cbor2';var Y=Object.defineProperty;var Z=(t,r)=>{for(var n in r)Y(t,n,{get:r[n],enumerable:true});};var $={encode(t){return o.encode(t)},decode(t){return o.decode(t)}};var X={};Z(X,{BadGateway:()=>V,BadRequest:()=>c,Base:()=>s,Conflict:()=>y,ContentTooLarge:()=>b,ExpectationFailed:()=>A,FailedDependency:()=>U,Forbidden:()=>d,GatewayTimeout:()=>K,Gone:()=>f,HTTPVersionNotSupported:()=>D,ImATeapot:()=>T,InsufficientStorage:()=>Q,InternalServerError:()=>L,LengthRequired:()=>R,Locked:()=>k,LoopDetected:()=>z,MethodNotAllowed:()=>x,MisdirectedRequest:()=>I,NetworkAuthenticationRequired:()=>W,NotAcceptable:()=>u,NotExtended:()=>J,NotFound:()=>g,NotImplemented:()=>F,PaymentRequired:()=>l,PreconditionFailed:()=>_,PreconditionRequired:()=>O,ProxyAuthenticationRequired:()=>m,RangeNotSatisfiable:()=>q,RequestHeaderFieldsTooLarge:()=>E,RequestTimeout:()=>h,ServiceUnavailable:()=>B,TooEarly:()=>H,TooManyRequests:()=>N,URITooLong:()=>v,Unauthorized:()=>a,UnavailableForLegalReasons:()=>j,UnprocessableEntity:()=>M,UnsupportedMediaType:()=>P,UpgradeRequired:()=>w,VariantAlsoNegotiates:()=>G});var p=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.OK=200]="OK",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.IMUsed=226]="IMUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.ContentTooLarge=413]="ContentTooLarge",e[e.URITooLong=414]="URITooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HTTPVersionNotSupported=505]="HTTPVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(p||{});var s=class extends Error{constructor(n){super(n.msg);this.payload=n;}status(n){return this.payload.status=n,this}code(n){return this.payload.code=n,this}msg(n){return this.payload.msg=n,this}},c=class extends s{constructor(r){super({status:400,code:"bad_request",msg:r});}},a=class extends s{constructor(r){super({status:401,code:"unauthorized",msg:r});}},l=class extends s{constructor(r){super({status:402,code:"payment_required",msg:r});}},d=class extends s{constructor(r){super({status:403,code:"forbidden",msg:r});}},g=class extends s{constructor(r){super({status:404,code:"not_found",msg:r});}},x=class extends s{constructor(r){super({status:405,code:"method_not_allowed",msg:r});}},u=class extends s{constructor(r){super({status:406,code:"not_acceptable",msg:r});}},m=class extends s{constructor(r){super({status:407,code:"proxy_authentication_required",msg:r});}},h=class extends s{constructor(r){super({status:408,code:"request_timeout",msg:r});}},y=class extends s{constructor(r){super({status:409,code:"conflict",msg:r});}},f=class extends s{constructor(r){super({status:410,code:"gone",msg:r});}},R=class extends s{constructor(r){super({status:411,code:"length_required",msg:r});}},_=class extends s{constructor(r){super({status:412,code:"precondition_failed",msg:r});}},b=class extends s{constructor(r){super({status:413,code:"content_too_large",msg:r});}},v=class extends s{constructor(r){super({status:414,code:"uri_too_long",msg:r});}},P=class extends s{constructor(r){super({status:415,code:"unsupported_media_type",msg:r});}},q=class extends s{constructor(r){super({status:416,code:"range_not_satisfiable",msg:r});}},A=class extends s{constructor(r){super({status:417,code:"expectation_failed",msg:r});}},T=class extends s{constructor(r){super({status:418,code:"im_a_teapot",msg:r});}},I=class extends s{constructor(r){super({status:421,code:"misdirected_request",msg:r});}},M=class extends s{constructor(r){super({status:422,code:"unprocessable_entity",msg:r});}},k=class extends s{constructor(r){super({status:423,code:"locked",msg:r});}},U=class extends s{constructor(r){super({status:424,code:"failed_dependency",msg:r});}},H=class extends s{constructor(r){super({status:425,code:"too_early",msg:r});}},w=class extends s{constructor(r){super({status:426,code:"upgrade_required",msg:r});}},O=class extends s{constructor(r){super({status:428,code:"precondition_required",msg:r});}},N=class extends s{constructor(r){super({status:429,code:"too_many_requests",msg:r});}},E=class extends s{constructor(r){super({status:431,code:"request_header_fields_too_large",msg:r});}},j=class extends s{constructor(r){super({status:451,code:"unavailable_for_legal_reasons",msg:r});}},L=class extends s{constructor(r){super({status:500,code:"internal_server_error",msg:r});}},F=class extends s{constructor(r){super({status:501,code:"not_implemented",msg:r});}},V=class extends s{constructor(r){super({status:502,code:"bad_gateway",msg:r});}},B=class extends s{constructor(r){super({status:503,code:"service_unavailable",msg:r});}},K=class extends s{constructor(r){super({status:504,code:"gateway_timeout",msg:r});}},D=class extends s{constructor(r){super({status:505,code:"http_version_not_supported",msg:r});}},G=class extends s{constructor(r){super({status:506,code:"variant_also_negotiates",msg:r});}},Q=class extends s{constructor(r){super({status:507,code:"insufficient_storage",msg:r});}},z=class extends s{constructor(r){super({status:508,code:"loop_detected",msg:r});}},J=class extends s{constructor(r){super({status:510,code:"not_extended",msg:r});}},W=class extends s{constructor(r){super({status:511,code:"network_authentication_required",msg:r});}};var i={get instance(){return globalThis.__M1CRO__.internals}};var C={fromId(t){return i.instance.providerFromId(t)}};var S={parse(t){return i.instance.parseAppId(t)}};export{S as AppId,C as Provider,p as StatusCode,$ as cbor,X as error};
@@ -0,0 +1,357 @@
1
+ import { SetCookie } from 'cookie';
2
+
3
+ type Record$1<K extends string | number | symbol = string, V = any> = {
4
+ [key in K]: V;
5
+ };
6
+ type Variant<K extends PropertyKey, T extends object> = {
7
+ [P in keyof T]: {
8
+ [Q in K]: P;
9
+ } & T[P] extends infer U ? {
10
+ [Q in keyof U]: U[Q];
11
+ } : never;
12
+ }[keyof T];
13
+ type EventHandler = <T>(event: string, data: T) => void | Promise<void>;
14
+ type Visibility = 'private' | 'platform' | 'vendor' | 'public';
15
+ interface Tenant {
16
+ id: string;
17
+ host: string;
18
+ }
19
+ interface AppId {
20
+ get name(): string;
21
+ get namespace(): Namespace;
22
+ toString(separator?: string): string;
23
+ }
24
+ declare const AppId: {
25
+ parse(input: string): AppId;
26
+ };
27
+ type Namespace = 'system' | 'platform' | {
28
+ vendor: string;
29
+ };
30
+ type AppRole = Variant<'type', AppRoleData>;
31
+ type AppRoleData = {
32
+ provider: {
33
+ group: string;
34
+ };
35
+ test: void;
36
+ };
37
+ interface Auth {
38
+ subject: Subject;
39
+ permissions: Permissions;
40
+ }
41
+ interface Subject {
42
+ id: string;
43
+ email: string;
44
+ roles: string[];
45
+ }
46
+ interface Permissions {
47
+ [key: string]: string[];
48
+ }
49
+ interface HookEventMap {
50
+ start: [];
51
+ install: [];
52
+ }
53
+
54
+ type InsertReturnMode = 'insertedIds' | 'documents';
55
+ type InsertReturnType<T extends Record$1, R extends InsertReturnMode> = R extends 'insertedIds' ? string[] : R extends 'documents' ? T[] : never;
56
+ interface InsertQuery<T extends Record$1 = Record$1, R extends InsertReturnMode = 'insertedIds'> extends PromiseLike<InsertReturnType<T, R>> {
57
+ return(mode: 'insertedIds'): InsertQuery<T, 'insertedIds'>;
58
+ return(mode: 'documents'): InsertQuery<T, 'documents'>;
59
+ return(mode: InsertReturnMode): InsertQuery<T, typeof mode>;
60
+ }
61
+ type InsertOneReturnMode = 'insertedId' | 'document';
62
+ type InsertOneReturnType<T extends Record$1, R extends InsertOneReturnMode> = R extends 'insertedId' ? string : R extends 'document' ? T : never;
63
+ interface InsertOneQuery<T extends Record$1 = Record$1, R extends InsertOneReturnMode = 'insertedId'> extends PromiseLike<InsertOneReturnType<T, R>> {
64
+ return(mode: 'insertedId'): InsertOneQuery<T, 'insertedId'>;
65
+ return(mode: 'document'): InsertOneQuery<T, 'document'>;
66
+ return(mode: InsertOneReturnMode): InsertOneQuery<T, typeof mode>;
67
+ }
68
+
69
+ type UpdateReturnMode = 'affectedRows' | 'oldDocuments' | 'newDocuments';
70
+ type UpdateReturnType<T, R extends UpdateReturnMode> = R extends 'affectedRows' ? bigint : R extends 'oldDocuments' | 'newDocuments' ? T[] : never;
71
+ interface UpdateQuery<T extends Record$1 = Record$1, R extends UpdateReturnMode = 'affectedRows'> extends PromiseLike<UpdateReturnType<T, R>> {
72
+ limit(limit: number): this;
73
+ offset(offset: number): this;
74
+ sort(sort: Sorting): this;
75
+ return(mode: 'affectedRows'): UpdateQuery<T, 'affectedRows'>;
76
+ return(mode: 'oldDocuments'): UpdateQuery<T, 'oldDocuments'>;
77
+ return(mode: 'newDocuments'): UpdateQuery<T, 'newDocuments'>;
78
+ return(mode: UpdateReturnMode): UpdateQuery<T, typeof mode>;
79
+ }
80
+ type UpdateOneReturnMode = 'success' | 'oldDocument' | 'newDocument';
81
+ type UpdateOneReturnType<T, R extends UpdateOneReturnMode> = R extends 'success' ? boolean : R extends 'oldDocument' | 'newDocument' ? T | undefined : never;
82
+ interface UpdateOneQuery<T extends Record$1 = Record$1, R extends UpdateOneReturnMode = 'success'> extends PromiseLike<UpdateOneReturnType<T, R>> {
83
+ offset(offset: number): this;
84
+ sort(sort: Sorting): this;
85
+ upsert(upsert: boolean): this;
86
+ return(mode: 'success'): UpdateOneQuery<T, 'success'>;
87
+ return(mode: 'oldDocument'): UpdateOneQuery<T, 'oldDocument'>;
88
+ return(mode: 'newDocument'): UpdateOneQuery<T, 'newDocument'>;
89
+ return(mode: UpdateOneReturnMode): UpdateOneQuery<T, typeof mode>;
90
+ }
91
+
92
+ type RemoveReturnMode = 'affectedRows' | 'documents';
93
+ type RemoveReturnType<T, R extends RemoveReturnMode> = R extends 'affectedRows' ? bigint : R extends 'documents' ? T[] : never;
94
+ interface RemoveQuery<T extends Record$1 = Record$1, R extends RemoveReturnMode = 'affectedRows'> extends PromiseLike<RemoveReturnType<T, R>> {
95
+ limit(limit: number): this;
96
+ offset(offset: number): this;
97
+ sort(sort: Sorting): this;
98
+ return(mode: 'affectedRows'): RemoveQuery<T, 'affectedRows'>;
99
+ return(mode: 'documents'): RemoveQuery<T, 'documents'>;
100
+ return(mode: RemoveReturnMode): RemoveQuery<T, typeof mode>;
101
+ }
102
+ type RemoveOneReturnMode = 'success' | 'document';
103
+ type RemoveOneReturnType<T, R extends RemoveOneReturnMode> = R extends 'success' ? boolean : R extends 'document' ? T | undefined : never;
104
+ interface RemoveOneQuery<T extends Record$1 = Record$1, R extends RemoveOneReturnMode = 'success'> extends PromiseLike<RemoveOneReturnType<T, R>> {
105
+ offset(offset: number): this;
106
+ sort(sort: Sorting): this;
107
+ return(mode: 'success'): RemoveOneQuery<T, 'success'>;
108
+ return(mode: 'document'): RemoveOneQuery<T, 'document'>;
109
+ return(mode: RemoveOneReturnMode): RemoveOneQuery<T, typeof mode>;
110
+ }
111
+
112
+ interface Entity<T extends object = Record$1<string, unknown>> {
113
+ get name(): string;
114
+ find(query?: Record$1): FindQuery<T>;
115
+ findOne(query?: Record$1): FindOneQuery<T>;
116
+ insert(docs: T[]): InsertQuery<T>;
117
+ insertOne(doc: T): InsertOneQuery<T>;
118
+ update(query: Record$1, update: Record$1): UpdateQuery<T>;
119
+ updateOne(query: Record$1, update: Record$1): UpdateOneQuery<T>;
120
+ remove(query: Record$1): RemoveQuery<T>;
121
+ removeOne(query: Record$1): RemoveOneQuery<T>;
122
+ }
123
+ interface Sorting {
124
+ [field: string]: 'asc' | 'desc';
125
+ }
126
+
127
+ interface FindQuery<T extends Record$1 = Record$1> extends PromiseLike<T[]> {
128
+ limit(limit: number): this;
129
+ offset(offset: number): this;
130
+ sort(sort: Sorting): this;
131
+ }
132
+ interface FindOneQuery<T extends Record$1 = Record$1> extends PromiseLike<T | undefined> {
133
+ offset(offset: number): this;
134
+ sort(sort: Sorting): this;
135
+ }
136
+
137
+ interface Artifacts {
138
+ get<T>(key: string): T | undefined;
139
+ set<T>(key: string, value: T): void;
140
+ delete(key: string): void;
141
+ get auth(): Auth | undefined;
142
+ }
143
+
144
+ type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
145
+ declare enum StatusCode {
146
+ Continue = 100,
147
+ SwitchingProtocols = 101,
148
+ Processing = 102,
149
+ EarlyHints = 103,
150
+ OK = 200,
151
+ Created = 201,
152
+ Accepted = 202,
153
+ NonAuthoritativeInformation = 203,
154
+ NoContent = 204,
155
+ ResetContent = 205,
156
+ PartialContent = 206,
157
+ MultiStatus = 207,
158
+ AlreadyReported = 208,
159
+ IMUsed = 226,
160
+ MultipleChoices = 300,
161
+ MovedPermanently = 301,
162
+ Found = 302,
163
+ SeeOther = 303,
164
+ NotModified = 304,
165
+ UseProxy = 305,
166
+ TemporaryRedirect = 307,
167
+ PermanentRedirect = 308,
168
+ BadRequest = 400,
169
+ Unauthorized = 401,
170
+ PaymentRequired = 402,
171
+ Forbidden = 403,
172
+ NotFound = 404,
173
+ MethodNotAllowed = 405,
174
+ NotAcceptable = 406,
175
+ ProxyAuthenticationRequired = 407,
176
+ RequestTimeout = 408,
177
+ Conflict = 409,
178
+ Gone = 410,
179
+ LengthRequired = 411,
180
+ PreconditionFailed = 412,
181
+ ContentTooLarge = 413,
182
+ URITooLong = 414,
183
+ UnsupportedMediaType = 415,
184
+ RangeNotSatisfiable = 416,
185
+ ExpectationFailed = 417,
186
+ ImATeapot = 418,
187
+ MisdirectedRequest = 421,
188
+ UnprocessableEntity = 422,
189
+ Locked = 423,
190
+ FailedDependency = 424,
191
+ TooEarly = 425,
192
+ UpgradeRequired = 426,
193
+ PreconditionRequired = 428,
194
+ TooManyRequests = 429,
195
+ RequestHeaderFieldsTooLarge = 431,
196
+ UnavailableForLegalReasons = 451,
197
+ InternalServerError = 500,
198
+ NotImplemented = 501,
199
+ BadGateway = 502,
200
+ ServiceUnavailable = 503,
201
+ GatewayTimeout = 504,
202
+ HTTPVersionNotSupported = 505,
203
+ VariantAlsoNegotiates = 506,
204
+ InsufficientStorage = 507,
205
+ LoopDetected = 508,
206
+ NotExtended = 510,
207
+ NetworkAuthenticationRequired = 511
208
+ }
209
+ type RequestHandler = (req: Request, res: ResponseBuilder) => void | Promise<void>;
210
+ type Middleware = (req: Request, res: ResponseBuilder, next: () => Promise<void>) => void | Promise<void>;
211
+ interface Router {
212
+ scope(path: string): Router;
213
+ route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;
214
+ middleware(handler: Middleware, options?: MiddlewareOptions): Router;
215
+ get(path: string, handler: RequestHandler, options?: RouteOptions): Router;
216
+ post(path: string, handler: RequestHandler, options?: RouteOptions): Router;
217
+ put(path: string, handler: RequestHandler, options?: RouteOptions): Router;
218
+ patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;
219
+ delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;
220
+ }
221
+ interface RouteOptions {
222
+ timeoutMs?: number;
223
+ permissions?: string[];
224
+ authenticated?: boolean;
225
+ visibility?: Visibility;
226
+ }
227
+ interface MiddlewareOptions {
228
+ path?: string;
229
+ priority?: number;
230
+ }
231
+ interface Request {
232
+ get artifacts(): Artifacts;
233
+ get method(): Method;
234
+ get url(): URL;
235
+ get params(): Record<string, string>;
236
+ get headers(): Headers;
237
+ cookie(name: string): string | undefined;
238
+ body(): Promise<Uint8Array>;
239
+ text(): Promise<string>;
240
+ json<T>(): Promise<T>;
241
+ }
242
+ interface RequestBuilder {
243
+ method(method: Method): this;
244
+ url(url: string | URL): this;
245
+ header(name: string, value: string): this;
246
+ headers(headers: HeadersInit): this;
247
+ cookie(name: string, value: string): this;
248
+ body(bytes: Uint8Array): this;
249
+ text(text: string): this;
250
+ json<T>(json: T): this;
251
+ }
252
+ interface Response {
253
+ get status(): number;
254
+ get headers(): Headers;
255
+ cookie(name: string): SetCookie | undefined;
256
+ body(): Promise<Uint8Array>;
257
+ text(): Promise<string>;
258
+ json<T>(): Promise<T>;
259
+ }
260
+ interface ResponseBuilder {
261
+ status(status: number): this;
262
+ header(name: string, value: string): this;
263
+ headers(headers: HeadersInit): this;
264
+ cookie(name: string, value?: string, options?: SetCookieOptions): this;
265
+ body(bytes: Uint8Array): this;
266
+ text(text: string): this;
267
+ json<T>(json: T): this;
268
+ }
269
+ interface SetCookieOptions {
270
+ encode?: (s: string) => string;
271
+ maxAge?: number;
272
+ expires?: Date;
273
+ domain?: string;
274
+ path?: string;
275
+ httpOnly?: boolean;
276
+ secure?: boolean;
277
+ partitioned?: boolean;
278
+ priority?: 'low' | 'medium' | 'high';
279
+ sameSite?: boolean | 'lax' | 'strict' | 'none';
280
+ }
281
+
282
+ interface Crypto {
283
+ deriveKey(seed: string, length: number): Uint8Array;
284
+ aesGcmEncrypt<T>(data: T): Uint8Array;
285
+ aesGcmDecrypt<T>(data: Uint8Array): T;
286
+ argon2Hash(algorithm: Argon2Algorithm, password: string, options?: Argon2Options): string;
287
+ argon2Verify(algorithm: Argon2Algorithm, password: string, hash: string, options?: Argon2Options): boolean;
288
+ }
289
+ type Argon2Algorithm = 'argon2d' | 'argon2i' | 'argon2id';
290
+ interface Argon2Options {
291
+ mCost?: number;
292
+ tCost?: number;
293
+ pCost?: number;
294
+ outputLen?: number;
295
+ }
296
+
297
+ interface SetOptions {
298
+ ttl?: number;
299
+ existenceCheck?: 'nx' | 'xx';
300
+ }
301
+ interface KeyValueStore {
302
+ get<T>(key: string): Promise<T>;
303
+ getDel<T>(key: string): Promise<T>;
304
+ set<T>(key: string, value: T, options?: SetOptions): Promise<void>;
305
+ delete(key: string): Promise<void>;
306
+ }
307
+
308
+ interface RPC {
309
+ call(url: string, method: Method): Call;
310
+ get(url: string): Call;
311
+ post(url: string): Call;
312
+ put(url: string): Call;
313
+ patch(url: string): Call;
314
+ delete(url: string): Call;
315
+ }
316
+ interface Call extends RequestBuilder, PromiseLike<Response> {
317
+ }
318
+
319
+ interface Providers {
320
+ list(group: string): Provider[];
321
+ }
322
+ interface Provider {
323
+ get app(): AppId;
324
+ get group(): string;
325
+ get id(): string;
326
+ call(path: string, method: Method): Call;
327
+ get(path: string): Call;
328
+ post(path: string): Call;
329
+ put(path: string): Call;
330
+ patch(path: string): Call;
331
+ delete(path: string): Call;
332
+ }
333
+ declare const Provider: {
334
+ fromId(id: string): Provider;
335
+ };
336
+
337
+ interface SSE {
338
+ push<T>(event: T, targets: string[]): Promise<void>;
339
+ }
340
+
341
+ interface Bridge {
342
+ get tenant(): Tenant;
343
+ get providers(): Providers;
344
+ settings<T>(): T | undefined;
345
+ crd<T>(key: string): T | undefined;
346
+ get rpc(): RPC;
347
+ get kv(): KeyValueStore;
348
+ get sse(): SSE;
349
+ get crypto(): Crypto;
350
+ entity<T extends object>(name: string): Entity<T>;
351
+ publish<T extends object>(event: string, payload: T, visibility?: Visibility[]): void;
352
+ }
353
+
354
+ declare const logLevels: readonly ["trace", "debug", "info", "warn", "error", "none"];
355
+ type LogLevel = (typeof logLevels)[number];
356
+
357
+ export { type AppRole as A, type Bridge as B, type EventHandler as E, type HookEventMap as H, type LogLevel as L, type Method as M, type Namespace as N, Provider as P, type Router as R, StatusCode as S, type Tenant as T, type Visibility as V, AppId as a, type Artifacts as b, type Auth as c, type Entity as d, type Middleware as e, type Providers as f, type Request as g, type RequestBuilder as h, type RequestHandler as i, type Response as j, type ResponseBuilder as k, type RouteOptions as l, type Subject as m };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m1cro/server-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-beta.11",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -18,7 +18,7 @@
18
18
  "access": "public"
19
19
  },
20
20
  "scripts": {
21
- "build": "yarn run typecheck && yarn run bundle",
21
+ "build": "yarn && yarn typecheck && yarn bundle",
22
22
  "typecheck": "tsc --noEmit",
23
23
  "bundle": "tsup --minify --treeshake smallest",
24
24
  "versioning": "yarn version --new-version",
@@ -32,4 +32,4 @@
32
32
  "devDependencies": {
33
33
  "tsup": "^8.5.1"
34
34
  }
35
- }
35
+ }
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"globals.js","sourcesContent":[]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cbor.ts"],"names":["cbor_default","data"],"mappings":"wBAEA,IAAOA,CAAAA,CAAQ,CACX,MAAA,CAAUC,CAAAA,CAAqB,CAC3B,OAAa,CAAA,CAAA,MAAA,CAAOA,CAAI,CAC5B,CAAA,CACA,OAAUA,CAAAA,CAAqB,CAC3B,OAAa,CAAA,CAAA,MAAA,CAAOA,CAAI,CAC5B,CACJ","file":"index.js","sourcesContent":["import * as cbor2 from \"cbor2\";\n\nexport default {\n encode<T>(data: T): Uint8Array {\n return cbor2.encode(data);\n },\n decode<T>(data: Uint8Array): T {\n return cbor2.decode(data);\n },\n};\n"]}