@furystack/rest-service 6.1.6 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/error-action.js.map +1 -1
- package/dist/actions/get-current-user.js.map +1 -1
- package/dist/actions/is-authenticated.js.map +1 -1
- package/dist/actions/login.js.map +1 -1
- package/dist/actions/logout.js.map +1 -1
- package/dist/actions/not-found-action.js.map +1 -1
- package/dist/api-manager.js.map +1 -1
- package/dist/authenticate.js.map +1 -1
- package/dist/authorize.js.map +1 -1
- package/dist/authorize.spec.js.map +1 -1
- package/dist/endpoint-generators/create-delete-endpoint.js.map +1 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.js.map +1 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-get-entity-endpoint.js.map +1 -1
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-patch-endpoint.js.map +1 -1
- package/dist/endpoint-generators/create-post-endpoint.js.map +1 -1
- package/dist/helpers.js.map +1 -1
- package/dist/http-authentication-settings.js.map +1 -1
- package/dist/http-user-context.js.map +1 -1
- package/dist/incoming-message-extensions.js.map +1 -1
- package/dist/rest-service.integration.spec.js +3 -2
- package/dist/rest-service.integration.spec.js.map +1 -1
- package/dist/schema-validator/schema-validator.js.map +1 -1
- package/dist/schema-validator/schema-validator.test.js.map +1 -1
- package/dist/server-manager.js.map +1 -1
- package/dist/utils.js +6 -2
- package/dist/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/actions/error-action.spec.ts +2 -2
- package/src/actions/error-action.ts +2 -1
- package/src/actions/get-current-user.spec.ts +1 -1
- package/src/actions/get-current-user.ts +4 -2
- package/src/actions/is-authenticated.spec.ts +1 -1
- package/src/actions/is-authenticated.ts +2 -1
- package/src/actions/login-action.spec.ts +1 -1
- package/src/actions/login.ts +3 -2
- package/src/actions/logout-action.spec.ts +1 -1
- package/src/actions/logout.ts +2 -1
- package/src/actions/not-found-action.spec.ts +1 -1
- package/src/actions/not-found-action.ts +2 -1
- package/src/add-cors-header.spec.ts +1 -1
- package/src/api-manager.ts +12 -7
- package/src/authenticate.spec.ts +2 -2
- package/src/authenticate.ts +2 -1
- package/src/authorize.spec.ts +4 -3
- package/src/authorize.ts +2 -1
- package/src/endpoint-generators/create-delete-endpoint.spec.ts +1 -1
- package/src/endpoint-generators/create-delete-endpoint.ts +4 -3
- package/src/endpoint-generators/create-get-collection-endpoint.spec.ts +3 -2
- package/src/endpoint-generators/create-get-collection-endpoint.ts +4 -3
- package/src/endpoint-generators/create-get-entity-endpoint.spec.ts +4 -2
- package/src/endpoint-generators/create-get-entity-endpoint.ts +5 -3
- package/src/endpoint-generators/create-patch-endpoint.spec.ts +1 -1
- package/src/endpoint-generators/create-patch-endpoint.ts +4 -3
- package/src/endpoint-generators/create-post-endpoint.spec.ts +1 -1
- package/src/endpoint-generators/create-post-endpoint.ts +6 -4
- package/src/endpoint-generators/utils.ts +1 -1
- package/src/helpers.ts +8 -6
- package/src/http-authentication-settings.ts +4 -2
- package/src/http-user-context.spec.ts +1 -1
- package/src/http-user-context.ts +4 -3
- package/src/incoming-message-extensions.ts +1 -0
- package/src/request-action-implementation.ts +3 -3
- package/src/rest-service.integration.spec.ts +4 -3
- package/src/rest.integration.test.ts +1 -1
- package/src/schema-validator/schema-validation-error.ts +1 -1
- package/src/schema-validator/schema-validator.test.ts +2 -1
- package/src/schema-validator/schema-validator.ts +2 -1
- package/src/server-manager.ts +5 -4
- package/src/server-response-extensions.ts +1 -1
- package/src/static-server-manager.ts +1 -1
- package/src/utils.ts +9 -4
- package/src/validate.integration.schema.ts +1 -1
- package/src/validate.integration.spec.ts +1 -1
- package/src/validate.ts +1 -1
- package/types/actions/error-action.d.ts +1 -1
- package/types/actions/error-action.d.ts.map +1 -1
- package/types/actions/get-current-user.d.ts +2 -2
- package/types/actions/get-current-user.d.ts.map +1 -1
- package/types/actions/is-authenticated.d.ts +1 -1
- package/types/actions/is-authenticated.d.ts.map +1 -1
- package/types/actions/login.d.ts +2 -2
- package/types/actions/login.d.ts.map +1 -1
- package/types/actions/logout.d.ts +1 -1
- package/types/actions/logout.d.ts.map +1 -1
- package/types/actions/not-found-action.d.ts +1 -1
- package/types/actions/not-found-action.d.ts.map +1 -1
- package/types/api-manager.d.ts +6 -6
- package/types/api-manager.d.ts.map +1 -1
- package/types/authenticate.d.ts +1 -1
- package/types/authenticate.d.ts.map +1 -1
- package/types/authorize.d.ts +1 -1
- package/types/authorize.d.ts.map +1 -1
- package/types/endpoint-generators/create-delete-endpoint.d.ts +3 -3
- package/types/endpoint-generators/create-delete-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/create-get-collection-endpoint.d.ts +3 -3
- package/types/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/create-get-entity-endpoint.d.ts +3 -3
- package/types/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/create-patch-endpoint.d.ts +3 -3
- package/types/endpoint-generators/create-patch-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/create-post-endpoint.d.ts +3 -3
- package/types/endpoint-generators/create-post-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/utils.d.ts +1 -1
- package/types/endpoint-generators/utils.d.ts.map +1 -1
- package/types/helpers.d.ts +6 -6
- package/types/helpers.d.ts.map +1 -1
- package/types/http-authentication-settings.d.ts +3 -2
- package/types/http-authentication-settings.d.ts.map +1 -1
- package/types/http-user-context.d.ts +3 -3
- package/types/http-user-context.d.ts.map +1 -1
- package/types/incoming-message-extensions.d.ts +1 -0
- package/types/incoming-message-extensions.d.ts.map +1 -1
- package/types/request-action-implementation.d.ts +3 -3
- package/types/request-action-implementation.d.ts.map +1 -1
- package/types/rest.integration.test.d.ts +1 -1
- package/types/rest.integration.test.d.ts.map +1 -1
- package/types/schema-validator/schema-validation-error.d.ts +1 -1
- package/types/schema-validator/schema-validation-error.d.ts.map +1 -1
- package/types/schema-validator/schema-validator.d.ts +1 -1
- package/types/schema-validator/schema-validator.d.ts.map +1 -1
- package/types/server-manager.d.ts +3 -3
- package/types/server-manager.d.ts.map +1 -1
- package/types/server-response-extensions.d.ts +1 -1
- package/types/server-response-extensions.d.ts.map +1 -1
- package/types/static-server-manager.d.ts +1 -1
- package/types/static-server-manager.d.ts.map +1 -1
- package/types/utils.d.ts +2 -2
- package/types/utils.d.ts.map +1 -1
- package/types/validate.d.ts +1 -1
- package/types/validate.d.ts.map +1 -1
- package/types/validate.integration.schema.d.ts +1 -1
- package/types/validate.integration.schema.d.ts.map +1 -1
package/src/authenticate.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isAuthenticated } from '@furystack/core'
|
|
2
2
|
import { sleepAsync } from '@furystack/utils'
|
|
3
3
|
import { HttpUserContext } from './http-user-context'
|
|
4
|
-
import { ActionResult,
|
|
4
|
+
import type { ActionResult, RequestAction, RequestActionOptions } from './request-action-implementation'
|
|
5
|
+
import { JsonResult } from './request-action-implementation'
|
|
5
6
|
|
|
6
7
|
export const Authenticate =
|
|
7
8
|
() =>
|
package/src/authorize.spec.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { IncomingMessage } from 'http'
|
|
1
|
+
import type { IncomingMessage } from 'http'
|
|
2
2
|
import { Injector } from '@furystack/inject'
|
|
3
3
|
import { usingAsync } from '@furystack/utils'
|
|
4
|
-
import { User
|
|
4
|
+
import type { User } from '@furystack/core'
|
|
5
|
+
import { IdentityContext } from '@furystack/core'
|
|
5
6
|
import { Authorize } from './authorize'
|
|
6
|
-
import { ServerResponse } from 'http'
|
|
7
|
+
import type { ServerResponse } from 'http'
|
|
7
8
|
import { EmptyResult } from './request-action-implementation'
|
|
8
9
|
|
|
9
10
|
describe('Authorize', () => {
|
package/src/authorize.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isAuthorized } from '@furystack/core'
|
|
2
2
|
import { sleepAsync } from '@furystack/utils'
|
|
3
|
-
import { ActionResult,
|
|
3
|
+
import type { ActionResult, RequestAction, RequestActionOptions } from './request-action-implementation'
|
|
4
|
+
import { JsonResult } from './request-action-implementation'
|
|
4
5
|
|
|
5
6
|
export const Authorize =
|
|
6
7
|
(...roles: string[]) =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { usingAsync } from '@furystack/utils'
|
|
2
2
|
import { Injector } from '@furystack/inject'
|
|
3
|
-
import { DeleteEndpoint } from '@furystack/rest'
|
|
3
|
+
import type { DeleteEndpoint } from '@furystack/rest'
|
|
4
4
|
import { createDeleteEndpoint } from './create-delete-endpoint'
|
|
5
5
|
import got from 'got'
|
|
6
6
|
import { MockClass, setupContext } from './utils'
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject'
|
|
2
|
-
import { DeleteEndpoint } from '@furystack/rest'
|
|
1
|
+
import type { Constructable } from '@furystack/inject'
|
|
2
|
+
import type { DeleteEndpoint } from '@furystack/rest'
|
|
3
3
|
import '@furystack/repository'
|
|
4
|
-
import {
|
|
4
|
+
import type { RequestAction } from '../request-action-implementation'
|
|
5
|
+
import { JsonResult } from '../request-action-implementation'
|
|
5
6
|
import { getRepository } from '@furystack/repository'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -3,8 +3,9 @@ import { Injector } from '@furystack/inject'
|
|
|
3
3
|
import got from 'got'
|
|
4
4
|
import { MockClass, setupContext } from './utils'
|
|
5
5
|
import { createGetCollectionEndpoint } from './create-get-collection-endpoint'
|
|
6
|
-
import { GetCollectionEndpoint, GetCollectionResult
|
|
7
|
-
import {
|
|
6
|
+
import type { GetCollectionEndpoint, GetCollectionResult } from '@furystack/rest'
|
|
7
|
+
import { serializeToQueryString } from '@furystack/rest'
|
|
8
|
+
import type { FindOptions } from '@furystack/core'
|
|
8
9
|
import { getDataSetFor, getRepository } from '@furystack/repository'
|
|
9
10
|
import { useRestService } from '../helpers'
|
|
10
11
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject'
|
|
2
|
-
import { GetCollectionEndpoint } from '@furystack/rest'
|
|
1
|
+
import type { Constructable } from '@furystack/inject'
|
|
2
|
+
import type { GetCollectionEndpoint } from '@furystack/rest'
|
|
3
3
|
import '@furystack/repository'
|
|
4
|
-
import {
|
|
4
|
+
import type { RequestAction } from '../request-action-implementation'
|
|
5
|
+
import { JsonResult } from '../request-action-implementation'
|
|
5
6
|
import { getRepository } from '@furystack/repository'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { usingAsync } from '@furystack/utils'
|
|
2
2
|
import { Injector } from '@furystack/inject'
|
|
3
|
-
import { GetEntityEndpoint
|
|
4
|
-
import
|
|
3
|
+
import type { GetEntityEndpoint } from '@furystack/rest'
|
|
4
|
+
import { serializeToQueryString } from '@furystack/rest'
|
|
5
|
+
import type { HTTPError } from 'got'
|
|
6
|
+
import got from 'got'
|
|
5
7
|
import { MockClass, setupContext } from './utils'
|
|
6
8
|
import { createGetEntityEndpoint } from './create-get-entity-endpoint'
|
|
7
9
|
import { getDataSetFor } from '@furystack/repository'
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject'
|
|
2
|
-
import {
|
|
1
|
+
import type { Constructable } from '@furystack/inject'
|
|
2
|
+
import type { GetEntityEndpoint } from '@furystack/rest'
|
|
3
|
+
import { RequestError } from '@furystack/rest'
|
|
3
4
|
import '@furystack/repository'
|
|
4
|
-
import {
|
|
5
|
+
import type { RequestAction } from '../request-action-implementation'
|
|
6
|
+
import { JsonResult } from '../request-action-implementation'
|
|
5
7
|
import { getRepository } from '@furystack/repository'
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { usingAsync } from '@furystack/utils'
|
|
2
2
|
import { Injector } from '@furystack/inject'
|
|
3
|
-
import { PatchEndpoint } from '@furystack/rest'
|
|
3
|
+
import type { PatchEndpoint } from '@furystack/rest'
|
|
4
4
|
import { createPatchEndpoint } from './create-patch-endpoint'
|
|
5
5
|
import got from 'got'
|
|
6
6
|
import { MockClass, setupContext } from './utils'
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject'
|
|
2
|
-
import { PatchEndpoint } from '@furystack/rest'
|
|
1
|
+
import type { Constructable } from '@furystack/inject'
|
|
2
|
+
import type { PatchEndpoint } from '@furystack/rest'
|
|
3
3
|
import '@furystack/repository'
|
|
4
4
|
import '../incoming-message-extensions'
|
|
5
|
-
import {
|
|
5
|
+
import type { RequestAction } from '../request-action-implementation'
|
|
6
|
+
import { JsonResult } from '../request-action-implementation'
|
|
6
7
|
import { getRepository } from '@furystack/repository'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { usingAsync } from '@furystack/utils'
|
|
2
2
|
import { Injector } from '@furystack/inject'
|
|
3
|
-
import { PostEndpoint } from '@furystack/rest'
|
|
3
|
+
import type { PostEndpoint } from '@furystack/rest'
|
|
4
4
|
import { createPostEndpoint } from './create-post-endpoint'
|
|
5
5
|
import got from 'got'
|
|
6
6
|
import { MockClass, setupContext } from './utils'
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject'
|
|
2
|
-
import {
|
|
1
|
+
import type { Constructable } from '@furystack/inject'
|
|
2
|
+
import type { PostEndpoint } from '@furystack/rest'
|
|
3
|
+
import { RequestError } from '@furystack/rest'
|
|
3
4
|
import '@furystack/repository'
|
|
4
5
|
import '../incoming-message-extensions'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import type { RequestAction } from '../request-action-implementation'
|
|
7
|
+
import { JsonResult } from '../request-action-implementation'
|
|
8
|
+
import type { WithOptionalId } from '@furystack/core'
|
|
7
9
|
import { getRepository } from '@furystack/repository'
|
|
8
10
|
/**
|
|
9
11
|
* Creates a POST endpoint for updating entities
|
package/src/helpers.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { User } from '@furystack/core'
|
|
2
|
-
import { Injector } from '@furystack/inject'
|
|
1
|
+
import type { User } from '@furystack/core'
|
|
2
|
+
import type { Injector } from '@furystack/inject'
|
|
3
3
|
import { HttpAuthenticationSettings } from './http-authentication-settings'
|
|
4
|
-
import { RestApi } from '@furystack/rest'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import type { RestApi } from '@furystack/rest'
|
|
5
|
+
import type { ImplementApiOptions } from './api-manager'
|
|
6
|
+
import { ApiManager } from './api-manager'
|
|
7
|
+
import type { DefaultSession } from './models/default-session'
|
|
8
|
+
import type { StaticServerOptions } from './static-server-manager'
|
|
9
|
+
import { StaticServerManager } from './static-server-manager'
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Sets up the @furystack/rest-service with the provided settings
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { PhysicalStore,
|
|
2
|
-
import {
|
|
1
|
+
import type { PhysicalStore, StoreManager } from '@furystack/core'
|
|
2
|
+
import { User } from '@furystack/core'
|
|
3
|
+
import type { Constructable } from '@furystack/inject'
|
|
4
|
+
import { Injectable } from '@furystack/inject'
|
|
3
5
|
import { DefaultSession } from './models/default-session'
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from 'http'
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'http'
|
|
2
2
|
import { usingAsync } from '@furystack/utils'
|
|
3
3
|
import { Injector } from '@furystack/inject'
|
|
4
4
|
import { User, StoreManager, InMemoryStore, addStore } from '@furystack/core'
|
package/src/http-user-context.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from 'http'
|
|
2
|
-
import { User
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'http'
|
|
2
|
+
import type { User } from '@furystack/core'
|
|
3
|
+
import { StoreManager } from '@furystack/core'
|
|
3
4
|
import { Injectable, Injected } from '@furystack/inject'
|
|
4
5
|
import { HttpAuthenticationSettings } from './http-authentication-settings'
|
|
5
|
-
import { DefaultSession } from './models/default-session'
|
|
6
|
+
import type { DefaultSession } from './models/default-session'
|
|
6
7
|
import { PasswordAuthenticator, UnauthenticatedError } from '@furystack/security'
|
|
7
8
|
import { randomBytes } from 'crypto'
|
|
8
9
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Injector } from '@furystack/inject'
|
|
2
|
-
import { ServerResponse } from 'http'
|
|
3
|
-
import { IncomingMessage } from 'http'
|
|
1
|
+
import type { Injector } from '@furystack/inject'
|
|
2
|
+
import type { ServerResponse } from 'http'
|
|
3
|
+
import type { IncomingMessage } from 'http'
|
|
4
4
|
|
|
5
5
|
export interface ActionResult<T> {
|
|
6
6
|
statusCode: number
|
|
@@ -2,7 +2,7 @@ import { Injector } from '@furystack/inject'
|
|
|
2
2
|
import './helpers'
|
|
3
3
|
import { usingAsync, PathHelper } from '@furystack/utils'
|
|
4
4
|
import { GetCurrentUser, IsAuthenticated, LoginAction, LogoutAction } from './actions'
|
|
5
|
-
import { RestApi } from '@furystack/rest'
|
|
5
|
+
import type { RestApi } from '@furystack/rest'
|
|
6
6
|
import { User, InMemoryStore, addStore } from '@furystack/core'
|
|
7
7
|
import { DefaultSession } from './models/default-session'
|
|
8
8
|
import got from 'got'
|
|
@@ -61,7 +61,8 @@ const prepareInjector = async (i: Injector) => {
|
|
|
61
61
|
'/logout': LogoutAction,
|
|
62
62
|
'/testPostBody': async (options) => {
|
|
63
63
|
const body = await options.getBody()
|
|
64
|
-
|
|
64
|
+
const body2 = await options.getBody()
|
|
65
|
+
return JsonResult({ bodyValue: body.value, body2Value: body2.value })
|
|
65
66
|
},
|
|
66
67
|
},
|
|
67
68
|
},
|
|
@@ -140,7 +141,7 @@ describe('@furystack/rest-service inregration tests', () => {
|
|
|
140
141
|
retry: 0,
|
|
141
142
|
})
|
|
142
143
|
expect(response.statusCode).toBe(200)
|
|
143
|
-
expect(JSON.parse(response.body)).toStrictEqual({ bodyValue: 'baz' })
|
|
144
|
+
expect(JSON.parse(response.body)).toStrictEqual({ bodyValue: 'baz', body2Value: 'baz' })
|
|
144
145
|
})
|
|
145
146
|
})
|
|
146
147
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Injector } from '@furystack/inject'
|
|
2
|
-
import { RestApi } from '@furystack/rest'
|
|
2
|
+
import type { RestApi } from '@furystack/rest'
|
|
3
3
|
import { createClient } from '@furystack/rest-client-got'
|
|
4
4
|
import { usingAsync } from '@furystack/utils'
|
|
5
5
|
import { JsonResult } from './request-action-implementation'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SchemaValidator } from './schema-validator'
|
|
2
|
-
import {
|
|
2
|
+
import type { BodyParameters, Language } from './validate-examples'
|
|
3
|
+
import { exampleSchema } from './validate-examples'
|
|
3
4
|
import { SchemaValidationError } from './schema-validation-error'
|
|
4
5
|
|
|
5
6
|
describe('ValidateSchema', () => {
|
package/src/server-manager.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Injectable } from '@furystack/inject'
|
|
2
|
-
import { Disposable } from '@furystack/utils'
|
|
3
|
-
import { Server
|
|
2
|
+
import type { Disposable } from '@furystack/utils'
|
|
3
|
+
import type { Server } from 'http'
|
|
4
|
+
import { createServer } from 'http'
|
|
4
5
|
import Semaphore from 'semaphore-async-await'
|
|
5
|
-
import { IncomingMessage, ServerResponse } from 'http'
|
|
6
|
-
import { Socket } from 'net'
|
|
6
|
+
import type { IncomingMessage, ServerResponse } from 'http'
|
|
7
|
+
import type { Socket } from 'net'
|
|
7
8
|
|
|
8
9
|
export interface ServerOptions {
|
|
9
10
|
hostName?: string
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Injectable, Injected } from '@furystack/inject'
|
|
2
2
|
import { createReadStream } from 'fs'
|
|
3
3
|
import { stat } from 'fs/promises'
|
|
4
|
-
import { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'http'
|
|
4
|
+
import type { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'http'
|
|
5
5
|
import { getMimeForFile } from './mime-types'
|
|
6
6
|
import { join, normalize, sep } from 'path'
|
|
7
7
|
import { ServerManager } from './server-manager'
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from 'http'
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'http'
|
|
2
2
|
import { Injectable } from '@furystack/inject'
|
|
3
|
-
import { CorsOptions } from './models/cors-options'
|
|
3
|
+
import type { CorsOptions } from './models/cors-options'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A collection of various HTTP API related utilities
|
|
@@ -8,6 +8,10 @@ import { CorsOptions } from './models/cors-options'
|
|
|
8
8
|
@Injectable({ lifetime: 'transient' })
|
|
9
9
|
export class Utils {
|
|
10
10
|
public async readPostBodyRaw(incomingMessage: IncomingMessage) {
|
|
11
|
+
if (!incomingMessage.readable) {
|
|
12
|
+
throw Error('Incoming message is not readable')
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
let body = ''
|
|
12
16
|
await new Promise<void>((resolve, reject) => {
|
|
13
17
|
incomingMessage.on('readable', () => {
|
|
@@ -33,8 +37,9 @@ export class Utils {
|
|
|
33
37
|
* @returns the parsed object from the post body
|
|
34
38
|
*/
|
|
35
39
|
public async readPostBody<T>(incomingMessage: IncomingMessage): Promise<T> {
|
|
36
|
-
const body = await this.readPostBodyRaw(incomingMessage)
|
|
37
|
-
|
|
40
|
+
const body = incomingMessage.postBody || JSON.parse(await this.readPostBodyRaw(incomingMessage))
|
|
41
|
+
incomingMessage.postBody = body
|
|
42
|
+
return body
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
/**
|
|
@@ -7,7 +7,7 @@ import { Validate } from './validate'
|
|
|
7
7
|
import './helpers'
|
|
8
8
|
|
|
9
9
|
import schema from './validate.integration.spec.schema.json'
|
|
10
|
-
import { ValidationApi } from './validate.integration.schema'
|
|
10
|
+
import type { ValidationApi } from './validate.integration.schema'
|
|
11
11
|
import { useRestService } from './helpers'
|
|
12
12
|
|
|
13
13
|
// To recreate: yarn ts-json-schema-generator -f tsconfig.json --no-type-check -p packages/rest-service/src/validate.integration.schema.ts -o packages/rest-service/src/validate.integration.spec.schema.json
|
package/src/validate.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionResult, RequestAction, RequestActionOptions } from './request-action-implementation'
|
|
1
|
+
import type { ActionResult, RequestAction, RequestActionOptions } from './request-action-implementation'
|
|
2
2
|
import { SchemaValidator } from './schema-validator'
|
|
3
3
|
|
|
4
4
|
export const Validate =
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-action.d.ts","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"error-action.d.ts","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;GAGG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1D,CAoBA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { User } from '@furystack/core';
|
|
2
|
-
import { RequestAction } from '../request-action-implementation';
|
|
1
|
+
import type { User } from '@furystack/core';
|
|
2
|
+
import type { RequestAction } from '../request-action-implementation';
|
|
3
3
|
/**
|
|
4
4
|
* Action that returns the current authenticated user
|
|
5
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../src/actions/get-current-user.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../src/actions/get-current-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAG3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC;IACzC,MAAM,EAAE,IAAI,CAAA;CACb,CAGC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-authenticated.d.ts","sourceRoot":"","sources":["../../src/actions/is-authenticated.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"is-authenticated.d.ts","sourceRoot":"","sources":["../../src/actions/is-authenticated.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE;QAAE,eAAe,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAGnF,CAAA"}
|
package/types/actions/login.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../helpers';
|
|
2
|
-
import { User } from '@furystack/core';
|
|
3
|
-
import { RequestAction } from '../request-action-implementation';
|
|
2
|
+
import type { User } from '@furystack/core';
|
|
3
|
+
import type { RequestAction } from '../request-action-implementation';
|
|
4
4
|
/**
|
|
5
5
|
* Action that logs in the current user
|
|
6
6
|
* Should be called with a JSON Post body with ``username`` and ``password`` fields.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;;;GAIG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,MAAM,EAAE,IAAI,CAAA;IACZ,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC7C,CAUA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/actions/logout.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/actions/logout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAG3D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"not-found-action.d.ts","sourceRoot":"","sources":["../../src/actions/not-found-action.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"not-found-action.d.ts","sourceRoot":"","sources":["../../src/actions/not-found-action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAGrE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAOvE,CAAA"}
|
package/types/api-manager.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Disposable } from '@furystack/utils';
|
|
2
|
-
import { RestApi } from '@furystack/rest';
|
|
3
|
-
import { Injector } from '@furystack/inject';
|
|
4
|
-
import { OnRequest } from './server-manager';
|
|
5
|
-
import { CorsOptions } from './models/cors-options';
|
|
1
|
+
import type { Disposable } from '@furystack/utils';
|
|
2
|
+
import type { RestApi } from '@furystack/rest';
|
|
3
|
+
import type { Injector } from '@furystack/inject';
|
|
4
|
+
import type { OnRequest } from './server-manager';
|
|
5
|
+
import type { CorsOptions } from './models/cors-options';
|
|
6
6
|
import './server-response-extensions';
|
|
7
|
-
import { RequestAction } from './request-action-implementation';
|
|
7
|
+
import type { RequestAction } from './request-action-implementation';
|
|
8
8
|
export declare type RestApiImplementation<T extends RestApi> = {
|
|
9
9
|
[TMethod in keyof T]: {
|
|
10
10
|
[TUrl in keyof T[TMethod]]: T[TMethod][TUrl] extends {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-manager.d.ts","sourceRoot":"","sources":["../src/api-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"api-manager.d.ts","sourceRoot":"","sources":["../src/api-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAIjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,8BAA8B,CAAA;AAIrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAEpE,oBAAY,qBAAqB,CAAC,CAAC,SAAS,OAAO,IAAI;KACpD,OAAO,IAAI,MAAM,CAAC,GAAG;SACnB,IAAI,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS;YAAE,MAAM,EAAE,OAAO,CAAA;SAAE,GAAG,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK;KACnH;CACF,CAAA;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,OAAO;IACpD,GAAG,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAC7B,QAAQ,EAAE,QAAQ,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAA;CAChD;AAED,oBAAY,WAAW,GAAG;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG;QACX,CAAC,CAAC,EAAE,MAAM,GAAG;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAA;SAAE,CAAA;KAC7E,CAAA;CACF,CAAA;AAED,oBAAY,gBAAgB,GAAG,SAAS,GAAG;IACzC,WAAW,EAAE,WAAW,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAA;CAChD,CAAA;AAED,qBACa,UAAW,YAAW,UAAU;IAC3C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiC;IAE/C,OAAO;IAId,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,UAAU;IAeL,MAAM,CAAC,CAAC,SAAS,OAAO,EAAE,EACrC,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,sBAAsB,GACvB,EAAE,mBAAmB,CAAC,CAAC,CAAC;IA6BlB,iBAAiB,CAAC,OAAO,EAAE;QAChC,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,gBAAgB,EAAE,MAAM,EAAE,CAAA;KAC3B,GAAG,OAAO;IASX,OAAO,CAAC,qBAAqB;YAWf,aAAa;YA0Db,SAAS;IA2BvB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;CAC/C"}
|
package/types/authenticate.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../src/authenticate.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../src/authenticate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,iCAAiC,CAAA;AAGxG,eAAO,MAAM,YAAY;YAEF,OAAO;gDAc3B,CAAA"}
|
package/types/authorize.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestAction } from './request-action-implementation';
|
|
1
|
+
import type { RequestAction } from './request-action-implementation';
|
|
2
2
|
export declare const Authorize: (...roles: string[]) => <T extends {
|
|
3
3
|
result: unknown;
|
|
4
4
|
}>(action: RequestAction<T>) => RequestAction<T>;
|
package/types/authorize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,iCAAiC,CAAA;AAGxG,eAAO,MAAM,SAAS,aACT,MAAM,EAAE;YACE,OAAO;gDAa3B,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject';
|
|
2
|
-
import { DeleteEndpoint } from '@furystack/rest';
|
|
1
|
+
import type { Constructable } from '@furystack/inject';
|
|
2
|
+
import type { DeleteEndpoint } from '@furystack/rest';
|
|
3
3
|
import '@furystack/repository';
|
|
4
|
-
import { RequestAction } from '../request-action-implementation';
|
|
4
|
+
import type { RequestAction } from '../request-action-implementation';
|
|
5
5
|
/**
|
|
6
6
|
* Creates a DELETE endpoint for removing entities
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-delete-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-delete-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"create-delete-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-delete-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB;;;mDAWhC,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject';
|
|
2
|
-
import { GetCollectionEndpoint } from '@furystack/rest';
|
|
1
|
+
import type { Constructable } from '@furystack/inject';
|
|
2
|
+
import type { GetCollectionEndpoint } from '@furystack/rest';
|
|
3
3
|
import '@furystack/repository';
|
|
4
|
-
import { RequestAction } from '../request-action-implementation';
|
|
4
|
+
import type { RequestAction } from '../request-action-implementation';
|
|
5
5
|
/**
|
|
6
6
|
* Creates a GetCollection endpoint for the given model. The model should have a Repository DataSet
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-get-collection-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-collection-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"create-get-collection-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-collection-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B;;;6CAcvC,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject';
|
|
2
|
-
import { GetEntityEndpoint } from '@furystack/rest';
|
|
1
|
+
import type { Constructable } from '@furystack/inject';
|
|
2
|
+
import type { GetEntityEndpoint } from '@furystack/rest';
|
|
3
3
|
import '@furystack/repository';
|
|
4
|
-
import { RequestAction } from '../request-action-implementation';
|
|
4
|
+
import type { RequestAction } from '../request-action-implementation';
|
|
5
5
|
/**
|
|
6
6
|
* Creates a simple Get Entity endpoint for a specified model.
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-get-entity-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-entity-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"create-get-entity-endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint-generators/create-get-entity-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,OAAO,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAIrE;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB;;;sDAenC,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Constructable } from '@furystack/inject';
|
|
2
|
-
import { PatchEndpoint } from '@furystack/rest';
|
|
1
|
+
import type { Constructable } from '@furystack/inject';
|
|
2
|
+
import type { PatchEndpoint } from '@furystack/rest';
|
|
3
3
|
import '@furystack/repository';
|
|
4
4
|
import '../incoming-message-extensions';
|
|
5
|
-
import { RequestAction } from '../request-action-implementation';
|
|
5
|
+
import type { RequestAction } from '../request-action-implementation';
|
|
6
6
|
/**
|
|
7
7
|
* Creates a PATCH endpoint for updating entities
|
|
8
8
|
*
|