Skip to content

Commit

Permalink
Merge pull request #1743 from demergent-labs/documentation
Browse files Browse the repository at this point in the history
Improving documentation
  • Loading branch information
lastmjs authored Apr 18, 2024
2 parents d12dc7f + 326e8fb commit 8cf55f7
Show file tree
Hide file tree
Showing 191 changed files with 4,201 additions and 795 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- if: contains(github.head_ref, 'release--')
name: Install dfx
run: |
DFXVM_INIT_YES=true DFX_VERSION=0.18.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
DFXVM_INIT_YES=true DFX_VERSION=0.19.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH
# TODO we should use some Action-specific bot account
- if: contains(github.head_ref, 'release--')
Expand Down Expand Up @@ -244,7 +244,7 @@ jobs:
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
name: Install dfx
run: |
DFXVM_INIT_YES=true DFX_VERSION=0.18.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
DFXVM_INIT_YES=true DFX_VERSION=0.19.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Large diffs are not rendered by default.

240 changes: 240 additions & 0 deletions docs/assets.html

Large diffs are not rendered by default.

333 changes: 333 additions & 0 deletions docs/authentication.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/azle.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/candid.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/candid_based_documentation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/canister_lifecycle.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/canisters_overview.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/caveats.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/cross_canister.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/cycles.html

Large diffs are not rendered by default.

272 changes: 272 additions & 0 deletions docs/debugging.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/deployment.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/deployment_candid_based.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/get_started.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/hello_world.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/http.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/installation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/internet_computer_overview.html

Large diffs are not rendered by default.

226 changes: 226 additions & 0 deletions docs/limitations.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/management_canister.html

Large diffs are not rendered by default.

620 changes: 558 additions & 62 deletions docs/print.html

Large diffs are not rendered by default.

234 changes: 234 additions & 0 deletions docs/project_structure.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/query_methods.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/bitcoin.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/accept_message.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/arg_data_raw.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/arg_data_raw_size.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/call.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/call_apis.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/call_raw.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/call_raw128.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/call_with_payment.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/call_with_payment128.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/caller.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/method_name.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/msg_cycles_accept.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/msg_cycles_accept128.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/msg_cycles_available.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/msg_cycles_available128.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/msg_cycles_refunded.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/msg_cycles_refunded128.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/notify.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/notify_raw.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/notify_with_payment_128.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/reject.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/reject_code.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/reject_message.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/reply.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/call_apis/reply_raw.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/blob.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/bool.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/candid.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/empty.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/float32.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/float64.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/func.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/int.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/int16.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/int32.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/int64.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/int8.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/nat.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/nat16.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/nat32.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/nat64.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/nat8.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/null.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/opt.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/principal.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/record.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/reserved.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/service.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/text.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/variant.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/candid/vec.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/candid_decode.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/candid_encode.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/canister_apis.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/canister_balance.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/canister_balance128.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/canister_id.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/canister_version.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/data_certificate.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/instruction_counter.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/is_controller.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/performance_counter.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/print.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/set_certified_data.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/time.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_apis/trap.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/canister_methods.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/heartbeat.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/http_request.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/http_request_update.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/init.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/inspect_message.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/post_upgrade.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/pre_upgrade.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/query.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/canister_methods/update.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/environment_variables.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/bitcoin_get_utxos.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/canister_status.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/create_canister.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/delete_canister.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/deposit_cycles.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/ecdsa_public_key.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/http_request.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/install_code.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/raw_rand.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/sign_with_ecdsa.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/start_canister.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/stop_canister.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/uninstall_code.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/management_canister/update_settings.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/plugins.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/reference.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable64_grow.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable64_read.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable64_size.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable64_write.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable_bytes.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable_grow.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable_memory.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable_read.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable_size.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable_structures.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/stable_memory/stable_write.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/timers/clear_timer.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/timers/set_timer.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/timers/set_timer_interval.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/timers/timers.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference/wasm_binary_optimization.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/reference_http/autoreload.html

Large diffs are not rendered by default.

240 changes: 240 additions & 0 deletions docs/reference_http/environment_variables.html

Large diffs are not rendered by default.

240 changes: 240 additions & 0 deletions docs/reference_http/native_compilation.html

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions docs/reference_http/reference.html

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion docs/rest_based_examples.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.json

Large diffs are not rendered by default.

303 changes: 0 additions & 303 deletions docs/server.html

This file was deleted.

388 changes: 388 additions & 0 deletions docs/servers.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/stable_structures.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/the_azle_book.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/timers.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/update_methods.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/composite_queries/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function get_tests(canister1: ActorSubclass<_SERVICE>): Test[] {
Ok: error
.toString()
.includes(
`Rejection code 3, Canister ${getCanisterId(
`Rejection code 5, Canister ${getCanisterId(
'canister2'
)} has no query method`
)
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ node --version
Install the dfx command line tools for managing ICP applications:

```bash
DFX_VERSION=0.18.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
DFX_VERSION=0.19.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
```

Check that the installation went smoothly by looking for clean output from the following command:
Expand Down
14 changes: 6 additions & 8 deletions examples/inspect_message/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function getTests(
test: async () => {
try {
const result = await inspectMessageCanister.accessible();

return {
Ok: result === true
};
Expand All @@ -28,14 +29,13 @@ export function getTests(
test: async () => {
try {
await inspectMessageCanister.inaccessible();

return {
Ok: false
};
} catch (error) {
} catch (error: any) {
return {
Ok: ((error as any).message as string).includes(
'IC0516'
)
Ok: error.message.includes('IC0406')
};
}
}
Expand All @@ -49,11 +49,9 @@ export function getTests(
return {
Ok: false
};
} catch (error) {
} catch (error: any) {
return {
Ok: ((error as any).message as string).includes(
'IC0503'
)
Ok: error.message.includes('IC0503')
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion the_azle_book/book/404.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/azle.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/candid.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/canisters_overview.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/cross_canister.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/cycles.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions the_azle_book/book/deployment.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/examples.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/http.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/installation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/internet_computer_overview.html

Large diffs are not rendered by default.

620 changes: 558 additions & 62 deletions the_azle_book/book/print.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/searchindex.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion the_azle_book/book/timers.html

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions the_azle_book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
- [Get Started](./get_started.md)
- [Examples](./rest_based_examples.md)
- [Deployment](./deployment.md)
- [Server](./server.md)
- [Assets]()
- [Debugging]()
- [Limitations]()
- [Authentication]()
- [Project Structure](./project_structure.md)
- [Servers](./servers.md)
- [Assets](./assets.md)
- [Authentication](./authentication.md)
- [Databases]()
- [fetch]()
- [npm]()
- [Cycles]()
- [Tokens]()
- [Bitcoin]()
- [Ethereum]()
- [Debugging](./debugging.md)
- [Limitations](./limitations.md)
- [Reference](./reference_http/reference.md)
- [Autoreload](./reference_http/autoreload.md)
- [Environment Variables](./reference_http/environment_variables.md)
- [Native Compilation](./reference_http/native_compilation.md)
- [Old Candid-based Documentation](./candid_based_documentation.md)
- [Azle (Beta)](./azle.md)
- [Internet Computer Overview](./internet_computer_overview.md)
Expand Down
53 changes: 13 additions & 40 deletions the_azle_book/src/assets.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Assets
# Assets TL;DR

You can specify static assets (essentially files and folders) to be automatically included in your canister during deploy. You can specify assets using the `assets` property of your `dfx.json` file:
You can automatically copy static assets (essentially files and folders) into your canister's filesystem during deploy by using the `assets`, `assets_large` and `build_assets` properties of the canister object in your project's `dfx.json` file.

Here's an example that copies the `src/frontend/dist` directory on the deploying machine into the `dist` directory of the canister, using the `assets` and `build_assets` properties:

```json
{
Expand Down Expand Up @@ -30,51 +32,22 @@ You can specify static assets (essentially files and folders) to be automaticall
}
```

Let's focus on the `assets` property:

```json
"assets": [["src/frontend/dist", "dist"]],
```
The `assets` property is an array of tuples, where the first element of the tuple is the source directory on the deploying machine, and the second element of the tuple is the destination directory in the canister. Use `assets` for total assets under ~90 MiB in size.

We are instructing Azle to include the `src/frontend/dist` directory at the `dist` directory of the Azle canister.
The `build_assets` property allows you to specify custom terminal commands that will run before Azle copies the assets into the canister. You can use `build_assets` to build your frontend code for example. In this case we are running `npm run build`, which refers to an npm script that we have specified in our `package.json` file.

Azle canisters have their own file system separate from their host (i.e. your computer). You must load files into the Azle file system somehow. Using the `assets` property of `dfx.json` is one of those ways. You can also manually upload files yourself by creating endpoints and using `fs` to write to the filesystem. To do this you will have to split all files into chunks of 2 MiB or less to upload them. We are working on a way to allow automatic uploading of files.
There is also an `assets_large` property that works similarly to the `assets` property, but allows for total assets up to ~2 GiB in size. We are working on increasing this limit further.

There is a ~90 MiB limit for the `assets` property. The hard limit for a single canister will be 400 GiB currently. We are working on a way to automatically upload files for you.
Once you have loaded assets into your canister, they are accessible from that canister's filesystem. Here's an example of using the Express static middleware to serve a frontend from the canister's filesystem:

```typescript
import { Server } from 'azle';
import express, { Request } from 'express';

let db = {
hello: ''
};

export default Server(() => {
const app = express();

app.use(express.json());

app.get('/db', (req, res) => {
res.json(db);
});
import express from 'express';

app.post('/db/update', (req: Request<any, any, typeof db>, res) => {
db = req.body;
const app = express();

res.json(db);
});

app.use(express.static('/dist'));

return app.listen();
});
```

```typescript
app.use(express.static('/dist'));
```

TODO show an example of chunk uploading? Maybe we should just implement a simple chunk uploader so that they could at least do it?
app.listen();
```

TODO also describe the build_assets property
Assuming the `/dist` directory in the canister has an appropriate `index.html` file, this canister would serve a frontend at its URL when loaded in a web browser.
154 changes: 154 additions & 0 deletions the_azle_book/src/authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Authentication TL;DR

Azle canisters can import `ic` from `azle` and use `ic.caller()` to get the [principal (public-key linked identifier)](https://internetcomputer.org/docs/current/references/ic-interface-spec#principal) of the initiator of an HTTP request. HTTP requests are anonymous (principal `2vxsx-fae`) by default, but authentication with web browsers (and maybe Node.js) can be done using a JWT-like API from `azle/http_client`.

First you import `toJwt` from `azle/http_client`:

```typescript
import { toJwt } from 'azle/http_client';
```

Then you use `fetch` and construct an `Authorization` header using an [@dfinity/agent](https://www.npmjs.com/package/@dfinity/agent) `Identity`:

```typescript
const response = await fetch(
`http://bkyz2-fmaaa-aaaaa-qaaaq-cai.localhost:8000/whoami`,
{
method: 'GET',
headers: [['Authorization', toJwt(this.identity)]]
}
);
```

Here's an example of the frontend of a simple web application using `azle/http_client` and [Internet Identity](https://internetcomputer.org/internet-identity):

```typescript
import { Identity } from '@dfinity/agent';
import { AuthClient } from '@dfinity/auth-client';
import { toJwt } from 'azle/http_client';
import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';

@customElement('azle-app')
export class AzleApp extends LitElement {
@property()
identity: Identity | null = null;

@property()
whoami: string = '';

connectedCallback() {
super.connectedCallback();
this.authenticate();
}

async authenticate() {
const authClient = await AuthClient.create();
const isAuthenticated = await authClient.isAuthenticated();

if (isAuthenticated === true) {
this.handleIsAuthenticated(authClient);
} else {
await this.handleIsNotAuthenticated(authClient);
}
}

handleIsAuthenticated(authClient: AuthClient) {
this.identity = authClient.getIdentity();
}

async handleIsNotAuthenticated(authClient: AuthClient) {
await new Promise((resolve, reject) => {
authClient.login({
identityProvider: import.meta.env.VITE_IDENTITY_PROVIDER,
onSuccess: resolve as () => void,
onError: reject,
windowOpenerFeatures: `width=500,height=500`
});
});

this.identity = authClient.getIdentity();
}

async whoamiUnauthenticated() {
const response = await fetch(
`${import.meta.env.VITE_CANISTER_ORIGIN}/whoami`
);
const responseText = await response.text();

this.whoami = responseText;
}

async whoamiAuthenticated() {
const response = await fetch(
`${import.meta.env.VITE_CANISTER_ORIGIN}/whoami`,
{
method: 'GET',
headers: [['Authorization', toJwt(this.identity)]]
}
);
const responseText = await response.text();

this.whoami = responseText;
}

render() {
return html`
<h1>Internet Identity</h1>
<h2>
Whoami principal:
<span id="whoamiPrincipal">${this.whoami}</span>
</h2>
<button
id="whoamiUnauthenticated"
@click=${this.whoamiUnauthenticated}
>
Whoami Unauthenticated
</button>
<button
id="whoamiAuthenticated"
@click=${this.whoamiAuthenticated}
.disabled=${this.identity === null}
>
Whoami Authenticated
</button>
`;
}
}
```

Here's an example of the backend of that same simple web application:

```typescript
import { ic } from 'azle';
import express from 'express';

const app = express();

app.get('/whoami', (req, res) => {
res.send(ic.caller().toString());
});

app.use(express.static('/dist'));

app.listen();
```

# Authentication

Examples:

- [fetch_ic](https://github.com/demergent-labs/azle/tree/main/examples/fetch_ic)
- [internet_identity](https://github.com/demergent-labs/azle/tree/main/examples/internet_identity)

## Under-the-hood

Authentication of ICP calls is done through signatures on messages. [@dfinity/agent](https://www.npmjs.com/package/@dfinity/agent) provides very nice abstractions for creating all of the required signatures in the correct formats when calling into canisters on ICP. Unfortunately this requires you to abandon traditional HTTP requests, as you must use the agent's APIs.

Azle attempts to enable you to perform traditional HTTP requests with traditional libraries. Currently Azle focuses on `fetch`. When importing `toJwt`, `azle/http_client` will overwrite the global `fetch` function and will intercept `fetch` requests that have `Authorization` headers with an `Identity` as a value.

Once intercepted, these requests are turned into `@dfinity/agent` requests that call [the http_request and http_request_update canister methods](https://internetcomputer.org/docs/current/references/http-gateway-protocol-spec) directly, thus performing all of the required client-side authentication work.

We are working to push for ICP to more natively understand JWTs for authentication, without the need to intercept `fetch` requests and convert them into agent requests.
Loading

0 comments on commit 8cf55f7

Please sign in to comment.