@m1cro/server-sdk 0.1.1-beta.5 → 0.1.1-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { SetCookie } from 'cookie';
1
2
  import { JSONSchema4 } from 'json-schema';
2
3
 
3
4
  interface Crypto {
@@ -32,9 +33,16 @@ interface Tenant {
32
33
  host: string;
33
34
  }
34
35
  interface AppId {
35
- namespace: string;
36
- app: string;
36
+ get name(): string;
37
+ get namespace(): Namespace;
38
+ toString(separator?: string): string;
37
39
  }
40
+ declare const AppId: {
41
+ parse(input: string): AppId;
42
+ };
43
+ type Namespace = 'system' | 'platform' | {
44
+ vendor: string;
45
+ };
38
46
  type AppRole = Variant<'type', AppRoleData>;
39
47
  type AppRoleData = {
40
48
  provider: {
@@ -100,6 +108,7 @@ type UpdateOneReturnType<T, R extends UpdateOneReturnMode> = R extends 'success'
100
108
  interface UpdateOneQuery<T extends Record$1 = Record$1, R extends UpdateOneReturnMode = 'success'> extends PromiseLike<UpdateOneReturnType<T, R>> {
101
109
  offset(offset: number): this;
102
110
  sort(sort: Sorting): this;
111
+ upsert(upsert: boolean): this;
103
112
  return(mode: 'success'): UpdateOneQuery<T, 'success'>;
104
113
  return(mode: 'oldDocument'): UpdateOneQuery<T, 'oldDocument'>;
105
114
  return(mode: 'newDocument'): UpdateOneQuery<T, 'newDocument'>;
@@ -145,6 +154,7 @@ interface Artifacts {
145
154
  get<T>(key: string): T | undefined;
146
155
  set<T>(key: string, value: T): void;
147
156
  delete(key: string): void;
157
+ get auth(): Auth | undefined;
148
158
  }
149
159
 
150
160
  type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
@@ -217,7 +227,7 @@ type Middleware = (this: App, req: Request, res: ResponseBuilder, next: () => Pr
217
227
  interface Router {
218
228
  scope(path: string): Router;
219
229
  route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;
220
- middleware(path: string, handler: Middleware, options?: MiddlewareOptions): Router;
230
+ middleware(handler: Middleware, options?: MiddlewareOptions): Router;
221
231
  get(path: string, handler: RequestHandler, options?: RouteOptions): Router;
222
232
  post(path: string, handler: RequestHandler, options?: RouteOptions): Router;
223
233
  put(path: string, handler: RequestHandler, options?: RouteOptions): Router;
@@ -231,6 +241,7 @@ interface RouteOptions {
231
241
  visibility?: Visibility;
232
242
  }
233
243
  interface MiddlewareOptions {
244
+ path?: string;
234
245
  priority?: number;
235
246
  }
236
247
  interface Request {
@@ -239,6 +250,7 @@ interface Request {
239
250
  get url(): URL;
240
251
  get params(): Record<string, string>;
241
252
  get headers(): Headers;
253
+ cookie(name: string): string | undefined;
242
254
  body(): Promise<Uint8Array>;
243
255
  text(): Promise<string>;
244
256
  json<T>(): Promise<T>;
@@ -248,6 +260,7 @@ interface RequestBuilder {
248
260
  url(url: string | URL): RequestBuilder;
249
261
  header(name: string, value: string): RequestBuilder;
250
262
  headers(headers: HeadersInit): RequestBuilder;
263
+ cookie(name: string, value: string): RequestBuilder;
251
264
  body(bytes: Uint8Array): RequestBuilder;
252
265
  text(text: string): RequestBuilder;
253
266
  json<T>(json: T): RequestBuilder;
@@ -255,6 +268,7 @@ interface RequestBuilder {
255
268
  interface Response {
256
269
  get status(): number;
257
270
  get headers(): Headers;
271
+ cookie(name: string): SetCookie | undefined;
258
272
  body(): Promise<Uint8Array>;
259
273
  text(): Promise<string>;
260
274
  json<T>(): Promise<T>;
@@ -263,10 +277,23 @@ interface ResponseBuilder {
263
277
  status(status: number): ResponseBuilder;
264
278
  header(name: string, value: string): ResponseBuilder;
265
279
  headers(headers: HeadersInit): ResponseBuilder;
280
+ cookie(name: string, value?: string, options?: SetCookieOptions): ResponseBuilder;
266
281
  body(bytes: Uint8Array): ResponseBuilder;
267
282
  text(text: string): ResponseBuilder;
268
283
  json<T>(json: T): ResponseBuilder;
269
284
  }
285
+ interface SetCookieOptions {
286
+ encode?: (s: string) => string;
287
+ maxAge?: number;
288
+ expires?: Date;
289
+ domain?: string;
290
+ path?: string;
291
+ httpOnly?: boolean;
292
+ secure?: boolean;
293
+ partitioned?: boolean;
294
+ priority?: "low" | "medium" | "high";
295
+ sameSite?: boolean | "lax" | "strict" | "none";
296
+ }
270
297
 
271
298
  interface SetOptions {
272
299
  ttl?: number;
@@ -279,14 +306,6 @@ interface KeyValueStore {
279
306
  delete(key: string): Promise<void>;
280
307
  }
281
308
 
282
- interface Providers {
283
- list(group: string): Provider[];
284
- }
285
- interface Provider {
286
- group: string;
287
- app: AppId;
288
- }
289
-
290
309
  interface RPC {
291
310
  call(url: string, method: Method): Call;
292
311
  get(url: string): Call;
@@ -298,6 +317,24 @@ interface RPC {
298
317
  interface Call extends RequestBuilder, PromiseLike<Response> {
299
318
  }
300
319
 
320
+ interface Providers {
321
+ list(group: string): Provider[];
322
+ }
323
+ interface Provider {
324
+ get app(): AppId;
325
+ get group(): string;
326
+ get id(): string;
327
+ call(path: string, method: Method): Call;
328
+ get(path: string): Call;
329
+ post(path: string): Call;
330
+ put(path: string): Call;
331
+ patch(path: string): Call;
332
+ delete(path: string): Call;
333
+ }
334
+ declare const Provider: {
335
+ fromId(id: string): Provider;
336
+ };
337
+
301
338
  interface SSE {
302
339
  push<T>(event: T, targets: string[]): Promise<void>;
303
340
  }
@@ -321,15 +358,15 @@ interface App {
321
358
  publish<T extends object>(event: string, payload: T, visibility?: Visibility[]): void;
322
359
  }
323
360
  interface AppBuilder {
361
+ get router(): Router;
324
362
  on<K extends keyof HookEventMap>(type: K, listener: (this: App, ...args: HookEventMap[K]) => unknown): AppBuilder;
325
363
  role(role: AppRole): AppBuilder;
326
364
  capability(app: string, permissions: string[]): AppBuilder;
327
365
  capabilities(capabilities: {
328
366
  [app: string]: string[];
329
367
  }): AppBuilder;
330
- routes(factory: (router: Router) => unknown): AppBuilder;
331
368
  entity(name: string, schema: JSONSchema4): AppBuilder;
332
369
  subscribe(pattern: string, handler: EventHandler): AppBuilder;
333
370
  }
334
371
 
335
- export { type App, type AppBuilder, type AppId, type AppRole, type Artifacts, type Auth, type Entity, type EntryPoint, type Method, type Middleware, type Providers, type Request, type RequestBuilder, type RequestHandler, type Response, type ResponseBuilder, type RouteOptions, type Router, StatusCode, type Tenant, _default as cbor };
372
+ export { type App, type AppBuilder, AppId, type AppRole, type Artifacts, type Auth, type Entity, type EntryPoint, type Method, type Middleware, Provider, type Providers, type Request, type RequestBuilder, type RequestHandler, type Response, type ResponseBuilder, type RouteOptions, type Router, StatusCode, type Tenant, _default as cbor };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import*as r from'cbor2';var p={encode(i){return r.encode(i)},decode(i){return r.decode(i)}};var n=(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))(n||{});export{n as StatusCode,p as cbor};//# sourceMappingURL=index.js.map
1
+ import*as i from'cbor2';var p={encode(r){return i.encode(r)},decode(r){return i.decode(r)}};var t=(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))(t||{});var n={get instance(){return globalThis.__M1CRO__.internals}};var o={fromId(r){return n.instance.providerFromId(r)}};var s={parse(r){return n.instance.parseAppId(r)}};export{s as AppId,o as Provider,t as StatusCode,p as cbor};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cbor.ts","../src/http.ts"],"names":["cbor_default","data","StatusCode"],"mappings":"wBAEA,IAAOA,CAAAA,CAAQ,CACb,MAAA,CAAUC,CAAAA,CAAqB,CAC7B,OAAa,CAAA,CAAA,MAAA,CAAOA,CAAI,CAC1B,EACA,MAAA,CAAUA,CAAAA,CAAqB,CAC7B,OAAa,CAAA,CAAA,MAAA,CAAOA,CAAI,CAC1B,CACF,ECHO,IAAKC,CAAAA,CAAAA,CAAAA,CAAAA,GAEVA,CAAAA,CAAAA,CAAAA,CAAA,QAAA,CAAW,GAAA,CAAA,CAAX,UAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,mBAAqB,GAAA,CAAA,CAArB,oBAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,UAAA,CAAa,GAAA,CAAA,CAAb,YAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,UAAA,CAAa,GAAA,CAAA,CAAb,YAAA,CAGAA,CAAAA,CAAAA,CAAAA,CAAA,EAAA,CAAK,GAAA,CAAA,CAAL,IAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,OAAA,CAAU,KAAV,SAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,QAAA,CAAW,GAAA,CAAA,CA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AA,CAAA,WAAA,CAAc,GAAA,CAAA,CAAd,aAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,6BAAA,CAAgC,GAAA,CAAA,CAAhC,gCAxEUA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA","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","import type { App } from '.';\nimport type { Artifacts } from './artifact';\nimport type * as types from './types';\n\nexport type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';\n\nexport enum StatusCode {\n // 1xx\n Continue = 100,\n SwitchingProtocols = 101,\n Processing = 102,\n EarlyHints = 103,\n\n // 2xx\n OK = 200,\n Created = 201,\n Accepted = 202,\n NonAuthoritativeInformation = 203,\n NoContent = 204,\n ResetContent = 205,\n PartialContent = 206,\n MultiStatus = 207,\n AlreadyReported = 208,\n IMUsed = 226,\n\n // 3xx\n MultipleChoices = 300,\n MovedPermanently = 301,\n Found = 302,\n SeeOther = 303,\n NotModified = 304,\n UseProxy = 305,\n // SwitchProxy = 306, // Deprecated\n TemporaryRedirect = 307,\n PermanentRedirect = 308,\n\n // 4xx\n BadRequest = 400,\n Unauthorized = 401,\n PaymentRequired = 402,\n Forbidden = 403,\n NotFound = 404,\n MethodNotAllowed = 405,\n NotAcceptable = 406,\n ProxyAuthenticationRequired = 407,\n RequestTimeout = 408,\n Conflict = 409,\n Gone = 410,\n LengthRequired = 411,\n PreconditionFailed = 412,\n ContentTooLarge = 413,\n URITooLong = 414,\n UnsupportedMediaType = 415,\n RangeNotSatisfiable = 416,\n ExpectationFailed = 417,\n ImATeapot = 418,\n MisdirectedRequest = 421,\n UnprocessableEntity = 422,\n Locked = 423,\n FailedDependency = 424,\n TooEarly = 425,\n UpgradeRequired = 426,\n PreconditionRequired = 428,\n TooManyRequests = 429,\n RequestHeaderFieldsTooLarge = 431,\n UnavailableForLegalReasons = 451,\n\n // 5xx\n InternalServerError = 500,\n NotImplemented = 501,\n BadGateway = 502,\n ServiceUnavailable = 503,\n GatewayTimeout = 504,\n HTTPVersionNotSupported = 505,\n VariantAlsoNegotiates = 506,\n InsufficientStorage = 507,\n LoopDetected = 508,\n NotExtended = 510,\n NetworkAuthenticationRequired = 511,\n}\n\nexport type RequestHandler = (\n this: App,\n req: Request,\n res: ResponseBuilder\n) => void | Promise<void>;\n\nexport type Middleware = (\n this: App,\n req: Request,\n res: ResponseBuilder,\n next: () => Promise<void>\n) => void | Promise<void>;\n\nexport interface Router {\n scope(path: string): Router;\n\n route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n middleware(path: string, handler: Middleware, options?: MiddlewareOptions): Router;\n\n get(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n post(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n put(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n}\n\nexport interface RouteOptions {\n timeoutMs?: number;\n permissions?: string[];\n authenticated?: boolean;\n visibility?: types.Visibility;\n}\n\nexport interface MiddlewareOptions {\n priority?: number;\n}\n\nexport interface Request {\n get artifacts(): Artifacts;\n get method(): Method;\n get url(): URL;\n get params(): Record<string, string>;\n get headers(): Headers;\n body(): Promise<Uint8Array>;\n text(): Promise<string>;\n json<T>(): Promise<T>;\n}\n\nexport interface RequestBuilder {\n method(method: Method): RequestBuilder;\n url(url: string | URL): RequestBuilder;\n header(name: string, value: string): RequestBuilder;\n headers(headers: HeadersInit): RequestBuilder;\n body(bytes: Uint8Array): RequestBuilder;\n text(text: string): RequestBuilder;\n json<T>(json: T): RequestBuilder;\n}\n\nexport interface Response {\n get status(): number;\n get headers(): Headers;\n body(): Promise<Uint8Array>;\n text(): Promise<string>;\n json<T>(): Promise<T>;\n}\n\nexport interface ResponseBuilder {\n status(status: number): ResponseBuilder;\n header(name: string, value: string): ResponseBuilder;\n headers(headers: HeadersInit): ResponseBuilder;\n body(bytes: Uint8Array): ResponseBuilder;\n text(text: string): ResponseBuilder;\n json<T>(json: T): ResponseBuilder;\n}\n"]}
1
+ {"version":3,"sources":["../src/cbor.ts","../src/http.ts","../src/internals.ts","../src/provider.ts","../src/types.ts"],"names":["cbor_default","data","StatusCode","internals_default","Provider","id","AppId","input"],"mappings":"wBAEA,IAAOA,CAAAA,CAAQ,CACb,MAAA,CAAUC,CAAAA,CAAqB,CAC7B,OAAa,SAAOA,CAAI,CAC1B,CAAA,CACA,MAAA,CAAUA,EAAqB,CAC7B,OAAa,CAAA,CAAA,MAAA,CAAOA,CAAI,CAC1B,CACF,ECFO,IAAKC,CAAAA,CAAAA,CAAAA,CAAAA,GAEVA,IAAA,QAAA,CAAW,GAAA,CAAA,CAAX,UAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,mBAAqB,GAAA,CAAA,CAArB,oBAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,UAAA,CAAa,KAAb,YAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,UAAA,CAAa,GAAA,CAAA,CAAb,aAGAA,CAAAA,CAAAA,CAAAA,CAAA,EAAA,CAAK,GAAA,CAAA,CAAL,IAAA,CACAA,IAAA,OAAA,CAAU,GAAA,CAAA,CAAV,SAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,SAAW,GAAA,CAAA,CAAX,UAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,2BAAA,CAA8B,KAA9B,6BAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,SAAA,CAAY,GAAA,CAAA,CAAZ,YACAA,CAAAA,CAAAA,CAAAA,CAAA,YAAA,CAAe,GAAA,CAAA,CAAf,cAAA,CACAA,IAAA,cAAA,CAAiB,GAAA,CAAA,CAAjB,gBAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,YAAc,GAAA,CAAA,CAA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data);\n },\n decode<T>(data: Uint8Array): T {\n return cbor2.decode(data);\n },\n};\n","import type { SetCookie } from 'cookie';\nimport type { App } from '.';\nimport type { Artifacts } from './artifact';\nimport type * as types from './types';\n\nexport type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';\n\nexport enum StatusCode {\n // 1xx\n Continue = 100,\n SwitchingProtocols = 101,\n Processing = 102,\n EarlyHints = 103,\n\n // 2xx\n OK = 200,\n Created = 201,\n Accepted = 202,\n NonAuthoritativeInformation = 203,\n NoContent = 204,\n ResetContent = 205,\n PartialContent = 206,\n MultiStatus = 207,\n AlreadyReported = 208,\n IMUsed = 226,\n\n // 3xx\n MultipleChoices = 300,\n MovedPermanently = 301,\n Found = 302,\n SeeOther = 303,\n NotModified = 304,\n UseProxy = 305,\n // SwitchProxy = 306, // Deprecated\n TemporaryRedirect = 307,\n PermanentRedirect = 308,\n\n // 4xx\n BadRequest = 400,\n Unauthorized = 401,\n PaymentRequired = 402,\n Forbidden = 403,\n NotFound = 404,\n MethodNotAllowed = 405,\n NotAcceptable = 406,\n ProxyAuthenticationRequired = 407,\n RequestTimeout = 408,\n Conflict = 409,\n Gone = 410,\n LengthRequired = 411,\n PreconditionFailed = 412,\n ContentTooLarge = 413,\n URITooLong = 414,\n UnsupportedMediaType = 415,\n RangeNotSatisfiable = 416,\n ExpectationFailed = 417,\n ImATeapot = 418,\n MisdirectedRequest = 421,\n UnprocessableEntity = 422,\n Locked = 423,\n FailedDependency = 424,\n TooEarly = 425,\n UpgradeRequired = 426,\n PreconditionRequired = 428,\n TooManyRequests = 429,\n RequestHeaderFieldsTooLarge = 431,\n UnavailableForLegalReasons = 451,\n\n // 5xx\n InternalServerError = 500,\n NotImplemented = 501,\n BadGateway = 502,\n ServiceUnavailable = 503,\n GatewayTimeout = 504,\n HTTPVersionNotSupported = 505,\n VariantAlsoNegotiates = 506,\n InsufficientStorage = 507,\n LoopDetected = 508,\n NotExtended = 510,\n NetworkAuthenticationRequired = 511,\n}\n\nexport type RequestHandler = (\n this: App,\n req: Request,\n res: ResponseBuilder\n) => void | Promise<void>;\n\nexport type Middleware = (\n this: App,\n req: Request,\n res: ResponseBuilder,\n next: () => Promise<void>\n) => void | Promise<void>;\n\nexport interface Router {\n scope(path: string): Router;\n\n route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n middleware(handler: Middleware, options?: MiddlewareOptions): Router;\n\n get(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n post(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n put(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n}\n\nexport interface RouteOptions {\n timeoutMs?: number;\n permissions?: string[];\n authenticated?: boolean;\n visibility?: types.Visibility;\n}\n\nexport interface MiddlewareOptions {\n path?: string;\n priority?: number;\n}\n\nexport interface Request {\n get artifacts(): Artifacts;\n get method(): Method;\n get url(): URL;\n get params(): Record<string, string>;\n get headers(): Headers;\n cookie(name: string): string | undefined;\n body(): Promise<Uint8Array>;\n text(): Promise<string>;\n json<T>(): Promise<T>;\n}\n\nexport interface RequestBuilder {\n method(method: Method): RequestBuilder;\n url(url: string | URL): RequestBuilder;\n header(name: string, value: string): RequestBuilder;\n headers(headers: HeadersInit): RequestBuilder;\n cookie(name: string, value: string): RequestBuilder;\n body(bytes: Uint8Array): RequestBuilder;\n text(text: string): RequestBuilder;\n json<T>(json: T): RequestBuilder;\n}\n\nexport interface Response {\n get status(): number;\n get headers(): Headers;\n cookie(name: string): SetCookie | undefined;\n body(): Promise<Uint8Array>;\n text(): Promise<string>;\n json<T>(): Promise<T>;\n}\n\nexport interface ResponseBuilder {\n status(status: number): ResponseBuilder;\n header(name: string, value: string): ResponseBuilder;\n headers(headers: HeadersInit): ResponseBuilder;\n cookie(name: string, value?: string, options?: SetCookieOptions): ResponseBuilder;\n body(bytes: Uint8Array): ResponseBuilder;\n text(text: string): ResponseBuilder;\n json<T>(json: T): ResponseBuilder;\n}\n\nexport interface SetCookieOptions {\n encode?: (s: string) => string;\n maxAge?: number;\n expires?: Date;\n domain?: string;\n path?: string;\n httpOnly?: boolean;\n secure?: boolean;\n partitioned?: boolean;\n priority?: \"low\" | \"medium\" | \"high\";\n sameSite?: boolean | \"lax\" | \"strict\" | \"none\";\n}\n\nexport type { SetCookie } from 'cookie';\n","import { Provider } from \"./provider\";\nimport type { AppId } from \"./types\";\n\nexport interface Internals {\n parseAppId(input: string): AppId;\n providerFromId(id: string): Provider;\n}\n\nexport default {\n get instance() {\n return (globalThis as any)[\"__M1CRO__\"][\"internals\"] as Internals;\n }\n}\n\n","import type { Method } from './http';\nimport internals from './internals';\nimport type { Call } from './rpc';\nimport type { AppId } from './types';\n\nexport interface Providers {\n list(group: string): Provider[];\n}\n\nexport interface Provider {\n get app(): AppId;\n get group(): string;\n get id(): string;\n call(path: string, method: Method): Call;\n get(path: string): Call;\n post(path: string): Call;\n put(path: string): Call;\n patch(path: string): Call;\n delete(path: string): Call;\n}\n\nexport const Provider = {\n fromId(id: string): Provider {\n return internals.instance.providerFromId(id);\n },\n};","import internals from './internals';\nimport type { App } from '.';\n\nexport type Record<K extends string | number | symbol = string, V = any> = {\n [key in K]: V;\n};\n\nexport type Variant<K extends PropertyKey, T extends object> = {\n [P in keyof T]: { [Q in K]: P } & T[P] extends infer U ? { [Q in keyof U]: U[Q] } : never;\n}[keyof T];\n\nexport type EventHandler = <T>(this: App, event: string, data: T) => void | Promise<void>;\n\nexport type Visibility = 'private' | 'platform' | 'vendor' | 'public';\n\nexport interface Tenant {\n id: string;\n host: string;\n}\n\nexport interface AppId {\n get name(): string;\n get namespace(): Namespace;\n toString(separator?: string): string;\n}\n\nexport const AppId = {\n parse(input: string): AppId {\n return internals.instance.parseAppId(input);\n },\n};\n\nexport type Namespace = 'system' | 'platform' | { vendor: string };\n\nexport type AppRole = Variant<'type', AppRoleData>;\n\nexport type AppRoleData = {\n provider: { group: string };\n test: void;\n};\n\nexport interface Auth {\n subject: Subject;\n permissions: Permissions;\n}\n\nexport interface Subject {\n id: string;\n email: string;\n roles: string[];\n}\n\nexport interface Permissions {\n [key: string]: string[];\n}\n\nexport interface HookEventMap {\n start: [];\n install: [];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m1cro/server-sdk",
3
- "version": "0.1.1-beta.5",
3
+ "version": "0.1.1-beta.7",
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",