Class: SquidService
A base class for all the different types of Squid backend services. This class serves as a container for the various methods implemented in the backend in order to customize the Squid backend for an application.
Constructors
constructor
• new SquidService(config
)
Parameters
Name | Type |
---|---|
config | ServiceGlobalConfig |
Properties
region
• Readonly
region: "us-east-1.aws"
| "ap-south-1.aws"
Your application's region. When developing locally, the region will be set to local
.
Accessors
assetsDirectory
• get
assetsDirectory(): string
Returns the assets directory for your application. To read more about the assets directory, see the Squid documentation.
Returns
string
the assets directory for your application.
context
• get
context(): RunContext
The context object for the current request. This object contains information about the current request, such as the current user, the IP address, the user agent used, the request headers, and more.
Returns
RunContext
secrets
• get
secrets(): Record
<string
, SecretValue
>
The list of your application's secrets as defined in the Squid Console.
Returns
Record
<string
, SecretValue
>
squid
• get
squid(): Squid
Returns the Squid client instance for your application.
Returns
Squid
the Squid client instance for your application.
Methods
assertIsAuthenticated
▸ assertIsAuthenticated(): void
Asserts that the current request is authenticated (using a user token or an API key).
Returns
void
Throws
UNAUTHORIZED if the current request is not authenticated.
createOpenApiResponse
▸ createOpenApiResponse(body?
, statusCode?
, headers?
): any
Constructs a response for an OpenAPI operation. This function is typically used within an OpenAPI handler.
Parameters
Name | Type | Description |
---|---|---|
body? | unknown | The payload of the response. If not provided, defaults to an empty string. |
statusCode? | number | The HTTP status code for the response. Defaults to 200 if a body is present, otherwise 204. |
headers? | Record <string , unknown > | An object containing response headers. Defaults to an empty object if not provided. |
Returns
any
The openapi response.
createWebhookResponse
▸ createWebhookResponse(body?
, statusCode?
, headers?
): any
A helper method to create a webhook response. This method should be used inside a webhook handler (function decorated with @webhook).
Parameters
Name | Type | Description |
---|---|---|
body? | unknown | The body of the response. |
statusCode? | number | The status code of the response. |
headers? | Record <string , unknown > | The headers of the response. |
Returns
any
The webhook response.
getApiKey
▸ getApiKey(): string
Returns the API key used by the backend for your application.
Returns
string
getApiKeyAuth
▸ getApiKeyAuth(): undefined
| AuthWithApiKey
Returns the auth object for the current request or undefined if unauthenticated or if using a user token.
Returns
undefined
| AuthWithApiKey
The auth object for the current request or undefined if unauthenticated or if using a user token.
getUserAuth
▸ getUserAuth(): undefined
| AuthWithBearer
Returns the auth object for the current request or undefined if unauthenticated or if using an API key.
Returns
undefined
| AuthWithBearer
The auth object for the current request or undefined if unauthenticated or if using an API key.
isAuthenticated
▸ isAuthenticated(): boolean
Returns true if the current request is authenticated (using a user token or an API key).
Returns
boolean
true if the current request is authenticated (using a user token or an API key).
throwOpenApiResponse
▸ throwOpenApiResponse(content
): never
Parameters
Name | Type |
---|---|
content | Partial <{ body : unknown ; headers : Record <string , unknown > ; statusCode : number }> |
Returns
never
throwWebhookResponse
▸ throwWebhookResponse(content
): never
Parameters
Name | Type |
---|---|
content | Partial <{ body : unknown ; headers : Record <string , unknown > ; statusCode : number }> |
Returns
never