generated from deco-sites/start
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: add loader visibility docs (#388)
- Loading branch information
1 parent
56c7c28
commit 43ec33a
Showing
3 changed files
with
174 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
since: 1.109.0 | ||
--- | ||
|
||
# Managing Loader/Action Access | ||
|
||
By default, all loaders and actions in deco.cx are publicly accessible. However, you may need to restrict access to certain loaders/actions that handle sensitive operations or private APIs. This guide explains how to control loader/action visibility. | ||
|
||
## Visibility Options | ||
|
||
There are two visibility levels available: | ||
|
||
- `private`: Can only be invoked server-side through `ctx.invoke` | ||
- `public`: Can be called from both server and client through: | ||
- Runtime `invoke` calls | ||
- Direct path access via `/live/invoke/{path/to/block.ts}` | ||
|
||
## Setting Default Visibility | ||
|
||
To set the visibility level for a loader/action, export a `defaultVisibility` variable: | ||
|
||
```typescript | ||
// Make the loader publicly accessible | ||
export const defaultVisibility = 'public' | ||
|
||
// Make the loader private (server-side only) | ||
export const defaultVisibility = 'private' | ||
``` | ||
|
||
## Overriding Visibility | ||
|
||
You can override the default visibility settings in your `fresh.config.ts` file using the `visibilityOverrides` option: | ||
|
||
```typescript | ||
import { defineConfig } from "$fresh/server.ts"; | ||
import { plugins } from "deco/plugins/deco.ts"; | ||
import manifest from "./manifest.gen.ts"; | ||
|
||
export default defineConfig({ | ||
plugins: plugins<typeof manifest>({ | ||
manifest, | ||
htmx: true, | ||
visibilityOverrides: { | ||
"site/loaders/minicart.ts": "public", | ||
"vtex/loaders/cart.ts": "private" | ||
}, | ||
}), | ||
}); | ||
``` | ||
|
||
## Security Best Practices | ||
|
||
When deciding visibility levels: | ||
|
||
### Use `private` for | ||
|
||
- Accessing private/internal APIs | ||
- Operations involving credentials or secrets | ||
- Processing sensitive user/business data | ||
- Backend integrations requiring authentication | ||
|
||
### Use `public` for | ||
|
||
- Reading public product data | ||
- Fetching public content | ||
- Client-side data loading | ||
- User-facing operations that don't expose sensitive data | ||
|
||
## Related Documentation | ||
|
||
- [Fetching Data](/docs/en/developing-guide/fetching-data) | ||
- [Client-side Data Loading](/docs/en/developing-capabilities/islands/fetching-data-client) | ||
- [Core Concepts: Loaders](/docs/en/concepts/loader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
since: 1.109.0 | ||
--- | ||
|
||
# Gerenciando Acesso de Loaders/Actions | ||
|
||
Por padrão, todos os loaders e actions no deco.cx são publicamente acessíveis. No entanto, você pode precisar restringir o acesso a certos loaders/actions que lidam com operações sensíveis ou APIs privadas. Este guia explica como controlar a visibilidade de loaders/actions. | ||
|
||
## Opções de Visibilidade | ||
|
||
Existem dois níveis de visibilidade disponíveis: | ||
|
||
- `private`: Pode ser invocado apenas no lado do servidor através do `ctx.invoke` | ||
- `public`: Pode ser chamado tanto do servidor quanto do cliente através de: | ||
- Chamadas `invoke` em tempo de execução | ||
- Acesso direto via path `/live/invoke/{path/to/block.ts}` | ||
|
||
## Definindo Visibilidade Padrão | ||
|
||
Para definir o nível de visibilidade de um loader/action, exporte uma variável `defaultVisibility`: | ||
|
||
```typescript | ||
// Torna o loader publicamente acessível | ||
export const defaultVisibility = 'public' | ||
|
||
// Torna o loader privado (apenas lado do servidor) | ||
export const defaultVisibility = 'private' | ||
``` | ||
|
||
## Sobrescrevendo Visibilidade | ||
|
||
Você pode sobrescrever as configurações de visibilidade padrão no seu arquivo `fresh.config.ts` usando a opção `visibilityOverrides`: | ||
|
||
```typescript | ||
import { defineConfig } from "$fresh/server.ts"; | ||
import { plugins } from "deco/plugins/deco.ts"; | ||
import manifest from "./manifest.gen.ts"; | ||
|
||
export default defineConfig({ | ||
plugins: plugins<typeof manifest>({ | ||
manifest, | ||
htmx: true, | ||
visibilityOverrides: { | ||
"site/loaders/minicart.ts": "public", | ||
"vtex/loaders/cart.ts": "private" | ||
}, | ||
}), | ||
}); | ||
``` | ||
|
||
## Boas Práticas de Segurança | ||
|
||
Ao decidir os níveis de visibilidade: | ||
|
||
### Use `private` para | ||
|
||
- Acessar APIs privadas/internas | ||
- Operações envolvendo credenciais ou segredos | ||
- Processamento de dados sensíveis de usuários/negócios | ||
- Integrações backend que requerem autenticação | ||
|
||
### Use `public` para | ||
|
||
- Leitura de dados públicos de produtos | ||
- Busca de conteúdo público | ||
- Carregamento de dados no lado do cliente | ||
- Operações voltadas ao usuário que não expõem dados sensíveis | ||
|
||
## Documentação Relacionada | ||
|
||
- [Buscando Dados](/docs/pt/developing-guide/fetching-data) | ||
- [Carregamento de Dados no Cliente](/docs/pt/developing-capabilities/islands/fetching-data-client) | ||
- [Conceitos Principais: Loaders](/docs/pt/concepts/loader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters