@squidcloud/backend
Classes
- AiChatbotMutationContext
- ApiCallContext
- DistributedLockContext
- GraphqlContext
- MutationContext
- QueryContext
- SquidProject
- SquidService
Interfaces
- ApiOptions
- CallApiRequest
- GeneralCondition
- InContextCondition
- LimiterOptions
- MongoNativeQueryContext
- NotInContextCondition
- OtherContextCondition
- QuotaLimitOptions
- RateLimitOptions
- RelationalNativeQueryContext
- SchedulerOptions
- ServiceGlobalConfig
- ServiceRequestConfig
- SquidFile
- TopicReadContext
- TopicWriteContext
- TriggerOptions
- TriggerRequest
- WebhookRequest
- WebhookResponse
Type Aliases
ActionMethodDecorator
Ƭ ActionMethodDecorator<U
>: <T>(target
: Object
, propertyName
: string
, descriptor
: TypedPropertyDescriptor
<T
>) => TypedPropertyDescriptor
<T
>
Type parameters
Name |
---|
U |
Type declaration
▸ <T
>(target
, propertyName
, descriptor
): TypedPropertyDescriptor
<T
>
Type parameters
Name | Type |
---|---|
T | extends U |
Parameters
Name | Type |
---|---|
target | Object |
propertyName | string |
descriptor | TypedPropertyDescriptor <T > |
Returns
TypedPropertyDescriptor
<T
>
AiFunctionAction
Ƭ AiFunctionAction<T
>: (params
: T
) => any
Type parameters
Name | Type |
---|---|
T | extends Record <string , any > = any |
Type declaration
▸ (params
): any
Parameters
Name | Type |
---|---|
params | T |
Returns
any
ApiHeaders
Ƭ ApiHeaders: Record
<string
, string
| number
| boolean
>
The headers of an API call.
ClientConnectionStateChangeAction
Ƭ ClientConnectionStateChangeAction: (clientId
: ClientId
, clientConnectionState
: ClientConnectionState
) => Promise
<void
> | void
Type declaration
▸ (clientId
, clientConnectionState
): Promise
<void
> | void
Parameters
Name | Type |
---|---|
clientId | ClientId |
clientConnectionState | ClientConnectionState |
Returns
Promise
<void
> | void
ContextCondition
Ƭ ContextCondition<Doc
, F
>: InContextCondition
<Doc
, F
> | NotInContextCondition
<Doc
, F
> | OtherContextCondition
<Doc
, F
>
A Context condition - a condition that replaces multiple '==' or '!=' conditions with 'in' and 'not in'.
Type parameters
Name | Type |
---|---|
Doc | extends DocumentData = any |
F | extends Paths <Doc > = Paths <Doc > |
ContextConditions
Ƭ ContextConditions<Doc
, F
>: ContextCondition
<Doc
, F
>[]
A list of context conditions
Type parameters
Name | Type |
---|---|
Doc | extends DocumentData = any |
F | extends Paths <Doc > = Paths <Doc > |
ContextOperator
Ƭ ContextOperator: Exclude
<Operator
, "=="
| "!="
> | "in"
| "not in"
ExecutableAction
Ƭ ExecutableAction: (...args
: any
[]) => any
Type declaration
▸ (...args
): any
Parameters
Name | Type |
---|---|
...args | any [] |
Returns
any
GeneralConditions
Ƭ GeneralConditions<Doc
, F
>: GeneralCondition
<Doc
, F
>[]
A list of general conditions.
Type parameters
Name | Type |
---|---|
Doc | extends DocumentData = any |
F | extends Paths <Doc > = Paths <Doc > |
GenericValue
Ƭ GenericValue<Doc
, F
, O
>: O
extends "in"
? DeepRecord
<Doc
>[F
][] | null
: O
extends "not in"
? DeepRecord
<Doc
>[F
][] | null
: DeepRecord
<Doc
>[F
] | null
A generic value that can exist in a query.
Type parameters
Name | Type |
---|---|
Doc | any |
F | extends Paths <Doc > = Paths <Doc > |
O | extends AllOperators = any |
LimitedAction
Ƭ LimitedAction: () => any
| Promise
<any
>
Type declaration
▸ (): any
| Promise
<any
>
Returns
any
| Promise
<any
>
LimiterConfig
Ƭ LimiterConfig: Object
Type declaration
Name | Type |
---|---|
quotaLimit? | number | QuotaLimitOptions | QuotaLimitOptions [] |
rateLimit? | number | RateLimitOptions | RateLimitOptions [] |
LimiterScope
Ƭ LimiterScope: "ip"
| "user"
| "global"
NativeQueryContext
Ƭ NativeQueryContext: RelationalNativeQueryContext
| MongoNativeQueryContext
NativeQueryRequestType
Ƭ NativeQueryRequestType: "relational"
| "mongo"
QuotaRenewPeriod
Ƭ QuotaRenewPeriod: "hourly"
| "daily"
| "weekly"
| "monthly"
| "quarterly"
| "annually"
SchedulerAction
Ƭ SchedulerAction: () => void
| Promise
<void
>
Type declaration
▸ (): void
| Promise
<void
>
Returns
void
| Promise
<void
>
SecureAiChatbotAction
Ƭ SecureAiChatbotAction<T
>: T
extends "all"
? () => boolean
| Promise
<boolean
> : T
extends "chat"
? (context
: AiChatbotChatContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
> : (context
: AiChatbotMutationContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
>
Type parameters
Name | Type |
---|---|
T | extends AiChatbotActionType |
SecureApiAction
Ƭ SecureApiAction: (context
: ApiCallContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
>
SecureDatabaseAction
Ƭ SecureDatabaseAction<T
>: T
extends "all"
? () => boolean
| Promise
<boolean
> : T
extends "read"
? (context
: QueryContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
> : (context
: MutationContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
>
Type parameters
Name | Type |
---|---|
T | extends DatabaseActionType |
SecureDistributedLockAction
Ƭ SecureDistributedLockAction: (context
: DistributedLockContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
>
SecureGraphQLAction
Ƭ SecureGraphQLAction: (context
: GraphqlContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
>
SecureNativeQueryAction
Ƭ SecureNativeQueryAction: (context
: NativeQueryContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
>
SecureStorageAction
Ƭ SecureStorageAction<T
>: T
extends "all"
? () => boolean
| Promise
<boolean
> : (context
: StorageContext
) => boolean
| Promise
<boolean
>
Type parameters
Name | Type |
---|---|
T | extends StorageActionType |
SecureTopicAction
Ƭ SecureTopicAction<T
>: T
extends "all"
? () => boolean
| Promise
<boolean
> : T
extends "read"
? (context
: TopicReadContext
) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
> : (context
: TopicWriteContext
<T
>) => boolean
| Promise
<boolean
> | () => boolean
| Promise
<boolean
>
Type parameters
Name | Type |
---|---|
T | extends TopicActionType |
TriggerAction
Ƭ TriggerAction: (request
: TriggerRequest
) => void
| Promise
<void
> | () => void
| Promise
<void
>
WebhookAction
Ƭ WebhookAction: (request
: WebhookRequest
) => any
| () => any
Functions
aiFunction
▸ aiFunction<ParamType
>(description
, params
): ActionMethodDecorator
<AiFunctionAction
<ParamType
>>
Decorator that marks a function for exposing it to the AI assistant. The function accepts a JSON object as described in the description of the function in the annotation.
TODO - add docs To read more about exposing an executable, see the documentation.
Type parameters
Name | Type |
---|---|
ParamType | extends Record <string , any > = any |
Parameters
Name | Type |
---|---|
description | string |
params | AiFunctionParam [] |
Returns
ActionMethodDecorator
<AiFunctionAction
<ParamType
>>
clientConnectionStateHandler
▸ clientConnectionStateHandler(): ActionMethodDecorator
<ClientConnectionStateChangeAction
>
Decorator that marks a function for handling a client connection state change
Returns
ActionMethodDecorator
<ClientConnectionStateChangeAction
>
executable
▸ executable(): ActionMethodDecorator
<ExecutableAction
>
Decorator that marks a function for exposing it as an executable. The function can accept any parameter that can be serialized to JSON and return any parameter that can be serialized to JSON.
Once the function is exposed, it can be called from the Squid Client SDK using the executeFunction
method.
To read more about exposing an executable, see the
documentation.
Returns
ActionMethodDecorator
<ExecutableAction
>
limiterConfigToOptions
▸ limiterConfigToOptions(config
): LimiterOptions
Convert LimiterConfig to LimiterOptions.
This decouples the required syntax for the developer from the internal implementation.
Parameters
Name | Type | Description |
---|---|---|
config | LimiterConfig | LimiterConfig to convert. |
Returns
limits
▸ limits(options
): ActionMethodDecorator
<LimitedAction
>
A decorator that can be used to rate/quota limit a function. In its simplest form, the decorator can take the query rate that is allowed for the given function and/or how many total calls are permitted and will enforce those limits.
It will either execute the function or return an Error if the rate/quota limits are exceeded.
Rate Limit behavior:
- The rate limit unit is QPS (Queries Per Second).
- Bursts of up to 3x the given rate are permitted.
- The consumption bucket refills gradually.
Quota Limit behavior:
- Has a
renewPeriod
field that defaults to "monthly". - The "monthly" period is defined as 30 days.
- The "quarterly" period is defined as 90 days.
- Renews occur at the top of the hour (##:00 for HH:mm).
- No carry-over of unused quota from one period to the next.
- Changes to the limit value for a specific limit combo (function & scope & renewPeriod) will reset the active count. For example, if a user has made 10 calls and the limit is changed from 20 to 15, the user will be able to make 15 more calls (not 5).
Limits can be defined with more specifics and multiple limits can be defined for a single function.
Examples:
- Basic definition using defaults:Defaults to "global" scope and "monthly" renewPeriod.
@limits({ rateLimit: 5 }) // Only rate limit.
@limits({ quotaLimit: 20 }) // Only quota limit.
@limits({ rateLimit: 5, quotaLimit: 20 }) // Both rate and quota. - As objects defining scope and renewPeriod:
@limits({
rateLimit: {
value: 5,
scope: 'global'
},
quotaLimit: {
value: 20,
scope: 'global',
renewPeriod: 'monthly'
}
}) - As arrays of objects defining scope and renewPeriod
@limits({
rateLimit: [
{ value: 5, scope: 'global' },
{ value: 2, scope: 'user' }
],
quotaLimit: [
{ value: 20, scope: 'global', renewPeriod: 'monthly' },
{ value: 5000, scope: 'ip', renewPeriod: 'annually' }
]
})
All matching limits are consumed for each call. For example, an "IP" scoped limit will be consumed in addition to a "global" scoped limit.
Parameters
Name | Type | Description |
---|---|---|
options | LimiterConfig | LimiterConfig object specifying what kind of limits are desired. |
Returns
ActionMethodDecorator
<LimitedAction
>
scheduler
▸ scheduler(id
, cronExpression
, exclusive?
): ActionMethodDecorator
<SchedulerAction
>
Decorator that marks a function as a scheduler. The function will be called according to the provided cron expression.
To read more about schedulers, see the documentation.
Parameters
Name | Type | Description |
---|---|---|
id | string | The ID of the scheduler. Should be unique. |
cronExpression | `${string} ${string} ${string} ${string} ${string}` | `${string} ${string} ${string} ${string}` | The cron expression (in UTC) to schedule the function on. |
exclusive? | boolean | Whether the scheduler should be exclusive. If set to true, the scheduler will not trigger if the previous scheduler is still running. Default: true. |
Returns
ActionMethodDecorator
<SchedulerAction
>
▸ scheduler(options
): ActionMethodDecorator
<SchedulerAction
>
Decorator that marks a function as a scheduler. The function will be called according to the provided cron expression.
To read more about schedulers, see the documentation.
Parameters
Name | Type |
---|---|
options | SchedulerOptions |
Returns
ActionMethodDecorator
<SchedulerAction
>
secureAiChatbot
▸ secureAiChatbot<T
>(integrationId
, type
, profileId?
): ActionMethodDecorator
<SecureAiChatbotAction
<T
>>
A decorator that can be used to secure an AI chatbot. The decorator takes the AI Chatbot
integration ID, the action type (chat
or mutate
), and an optional profile ID. If no profile ID
is provided, the function will secure all requests to the integration (for the given action type).
The function should return a boolean or a Promise
of a boolean indicating
whether the action is allowed.
The function takes a context object as a parameter. The context object contains information about the action.
To read more about securing an AI chatbot, see the documentation.
Type parameters
Name | Type |
---|---|
T | extends AiChatbotActionType |
Parameters
Name | Type | Description |
---|---|---|
integrationId | string | The ID of the integration to secure. |
type | T | The type of action to secure. |
profileId? | string | The ID of the profile to secure. |
Returns
ActionMethodDecorator
<SecureAiChatbotAction
<T
>>
secureApi
▸ secureApi(integrationId
, endpointId?
): ActionMethodDecorator
<SecureApiAction
>
Decorator that marks a function for securing an API or an endpoint inside an API. The decorator takes the API integration ID, and an optional endpoint ID. If no endpoint ID is provided, the function will secure the whole API.
The function should return a boolean or a Promise
of a boolean indicating
whether the action is allowed.
The function takes a context object as a parameter. The context object contains information about the action.
To read more about securing an API, see the documentation.
Parameters
Name | Type | Description |
---|---|---|
integrationId | string | The ID of the integration to secure. |
endpointId? | string | The ID of the endpoint to secure. |
Returns
ActionMethodDecorator
<SecureApiAction
>
secureCollection
▸ secureCollection<T
>(collectionName
, type
, integrationId?
): ActionMethodDecorator
<SecureDatabaseAction
<T
>>
Decorator that marks a function for securing a collection inside a database.
The decorator takes the collection, type of action, and an optional integration ID.
If no integration ID is provided, the built_in_db
integration is used.
The function should return a boolean or a Promise
of a boolean indicating
whether the action is allowed.
In addition, depending on the action, the function can take a context object
as a parameter. The context object contains information about the action.
To read more about securing a collection rules, see the documentation.
Type parameters
Name | Type |
---|---|
T | extends DatabaseActionType |
Parameters
Name | Type | Description |
---|---|---|
collectionName | string | The name of the collection to secure. |
type | T | The type of action to secure. |
integrationId? | string | The ID of the integration to secure. |
Returns
ActionMethodDecorator
<SecureDatabaseAction
<T
>>
secureDatabase
▸ secureDatabase<T
>(type
, integrationId?
): ActionMethodDecorator
<SecureDatabaseAction
<T
>>
Decorator that marks a function for securing a database.
The decorator takes a type of action and an optional integration ID.
If no integration ID is provided, the built_in_db
integration is used.
The function should return a boolean or a Promise
of a boolean indicating
whether the action is allowed.
In addition, depending on the action, the function can take a context object
as a parameter. The context object contains information about the action.
To read more about securing a database, see the documentation.
Type parameters
Name | Type |
---|---|
T | extends DatabaseActionType |
Parameters
Name | Type | Description |
---|---|---|
type | T | The type of action to secure. |
integrationId? | string | The ID of the integration to secure. |
Returns
ActionMethodDecorator
<SecureDatabaseAction
<T
>>
secureDistributedLock
▸ secureDistributedLock(mutex?
): ActionMethodDecorator
<SecureDistributedLockAction
>
A decorator that can be used to secure a distributed lock. Distributed locks are secured by default and can be
invoked only if the decorated function allows it. The function returns a boolean or a Promise
of a boolean that
indicates whether the lock can be acquired or not.
The function accepts a context object as a parameter. The context object contains information about the mutex and the request.
Parameters
Name | Type | Description |
---|---|---|
mutex? | string | The mutex to lock on. If none provided, the rule will apply for all mutexes. |
Returns
ActionMethodDecorator
<SecureDistributedLockAction
>
secureGraphQL
▸ secureGraphQL(integrationId
): ActionMethodDecorator
<SecureGraphQLAction
>
Decorator that marks a function for securing a GraphQL integration.
The function should return a boolean or a Promise
of a boolean indicating
whether the action is allowed.
The function takes a context object as a parameter. The context object contains information about the action.
To read more about securing a GraphQL integration, see the documentation.
Parameters
Name | Type |
---|---|
integrationId | string |
Returns
ActionMethodDecorator
<SecureGraphQLAction
>
secureNativeQuery
▸ secureNativeQuery(integrationId
): ActionMethodDecorator
<SecureNativeQueryAction
>
A decorator that can be used to secure a native query. Native queries are not secured by default and must be
explicitly secured using this decorator. The decorated function must return a boolean or a Promise
of a boolean
that indicates whether the query can be executed or not.
The function accepts a context object as a parameter. The context object contains information about the query.
To read more about securing a Native Query, see the documentation.
Parameters
Name | Type | Description |
---|---|---|
integrationId | string | The database integration ID. |
Returns
ActionMethodDecorator
<SecureNativeQueryAction
>
A decorator function that can be used to secure a native query.
secureStorage
▸ secureStorage<T
>(type
, integrationId?
): ActionMethodDecorator
<SecureStorageAction
<T
>>
Type parameters
Name | Type |
---|---|
T | extends StorageActionType |
Parameters
Name | Type |
---|---|
type | T |
integrationId? | string |
Returns
ActionMethodDecorator
<SecureStorageAction
<T
>>
secureTopic
▸ secureTopic<T
>(topicName
, type
, integrationId?
): ActionMethodDecorator
<SecureTopicAction
<T
>>
Decorator that marks a function for securing a topic in a message queue.
The decorator takes the topic name, type of action, and an optional integration ID.
If no integration ID is provided, the built_in_queue
integration is used.
The function should return a boolean or a Promise
of a boolean indicating
whether the action is allowed.
To read more about securing a topic, see the documentation.
Type parameters
Name | Type |
---|---|
T | extends TopicActionType |
Parameters
Name | Type | Description |
---|---|---|
topicName | string | The name of the topic to secure. |
type | T | The type of action to secure. |
integrationId? | string | The ID of the integration to secure. |
Returns
ActionMethodDecorator
<SecureTopicAction
<T
>>
trigger
▸ trigger(id
, collectionName
, integrationId?
): ActionMethodDecorator
<TriggerAction
>
Decorator that marks a function as a trigger to a change in a collection. The function will be called each time a change is made to the collection. The function accepts a context object as a parameter. The context object contains information about the change.
To read more about triggers, see the documentation.
Parameters
Name | Type | Description |
---|---|---|
id | string | The ID of the trigger. Should be unique. |
collectionName | string | The name of the collection to trigger on. |
integrationId? | string | The ID of the integration to trigger on. If not provided, the built_in_db integration is used. |
Returns
ActionMethodDecorator
<TriggerAction
>
▸ trigger(options
): ActionMethodDecorator
<TriggerAction
>
Decorator that marks a function as a trigger to a change in a collection. The function will be called each time a change is made to the collection. The function accepts a context object as a parameter. The context object contains information about the change.
To read more about triggers, see the documentation.
Parameters
Name | Type |
---|---|
options | TriggerOptions |
Returns
ActionMethodDecorator
<TriggerAction
>
webhook
▸ webhook(id
): ActionMethodDecorator
<WebhookAction
>
Decorator that marks a function as a webhook. The function will be called when a webhook is triggered.
Once the webhook is created, it will be exposed as a URL with the provided webhook ID with this format:
https://<your app Id>.<app region>.squid.cloud/webhooks/<webhook-id>
.
The function accepts a context object as a parameter. The context object contains information about the webhook.
The function can return any value that can be serialized to JSON or a WebhookResponse
object that can be created
using:
this.createWebhookResponse(<params>)
.
To read more about webhooks, see the documentation.
Parameters
Name | Type | Description |
---|---|---|
id | string | The ID of the webhook. Should be unique. |