Build an Attendee Count App
Build a small read-only App that displays an attendee total without rendering an attendee roster. This connects the declared grant, installed page context, minimal scalar field selection, response validation and asynchronous error handling. A count-only screen still needs a real data-permission review: hiding rows does not stop those rows crossing the network.
1. Prepare the app and intended scope
Follow Create Your First App to create an editable App with a repository/scaffold. Use the reviewed DevTools 2.1.40 source and a compatible Vue 3 environment. Use the standard scaffold's @/stores/gxpPortalConfigStore import: the reviewed production bundler maps it to the installed host store. The AI scaffold's @gx-runtime variant instead bundled a local store in the package check; do not substitute that variant. Do not create a second store or put a project API key in browser code.
This example deliberately requests a project-wide attendee total. It is not the count of one bound attendee, an allowed group, registered form responses or a page's current viewers. Obtain approval for that scope. For a narrower population, design and verify its actual server query/scoping separately rather than reusing this grant and filtering the display locally.
Add this contribution to the complete manifest's dependencies array, preserving unrelated required manifest fields:
[{"model":"Attendee","identifiers":["*"],"permissions":["view_attendees:viewAny"],"visibleFields":["id"]}]
* and :viewAny intentionally allow the project-wide population; they are not selected-record constraints. visibleFields: ["id"] is a nonempty scalar selection for participating page-principal serializers. Inspect all other Attendee dependencies, matching rule contributions, principal types, nested resources and the exact response. An empty list is not equivalent, and an additional explicit field list can widen the per-model ceiling. See Permissions and Dependencies.
This operation needs project context, not a record path binding, so the call below supplies a null dependency identifier. The declared model grant is still necessary. Do not replace it with a UI permission flag, relabel a resource binding as a Project or override team/project path values to cross contexts.
2. Implement the component
Use the discovered attendee index operation portal.v1.project.attendees.index and request one row with limit: 1. This reduces the page size; it is not a privacy boundary. Verify the returned meta.total and actual row keys before using it in a published integration.
<script setup>
import { ref, watch, onBeforeUnmount } from 'vue'
import { useGxpStore } from '@/stores/gxpPortalConfigStore'
const store = useGxpStore()
const status = ref('idle')
const total = ref(null)
const message = ref('')
let generation = 0
async function load() {
const requestGeneration = ++generation
total.value = null
message.value = ''
const project = store.pluginVars?.projectId
if (typeof project !== 'string' || !/^[^/]+\/[^/]+$/.test(project)) {
status.value = 'configuration'
message.value = store.getString('count_configuration', 'Configure the project before loading the count.')
return
}
status.value = 'loading'
try {
const result = await store.callApi('portal.v1.project.attendees.index', null, { limit: 1 })
if (requestGeneration !== generation) return
const value = result?.meta?.total
if (!Number.isSafeInteger(value) || value < 0) throw new Error('Invalid count')
total.value = value
status.value = 'ready'
} catch (error) {
if (requestGeneration !== generation) return
status.value = 'error'
message.value = error?.status === 403 || error?.status === 404
? store.getString('count_denied', 'The count is unavailable for this page or account.')
: store.getString('count_error', 'The count could not be loaded. Try again later.')
}
}
watch(
() => [store.pluginVars?.projectId, store.dependencyList, store.permissionFlags, store.auth?.user],
load,
{ immediate: true, deep: true },
)
onBeforeUnmount(() => { generation += 1 })
</script>
<template>
<section>
<h1>{{ store.getString('count_title', 'Attendee count') }}</h1>
<p role="status" aria-live="polite">
<template v-if="status === 'ready'">{{ total }}</template>
<template v-else-if="status === 'loading'">{{ store.getString('count_loading', 'Loading count…') }}</template>
<template v-else>{{ message }}</template>
</p>
<button type="button" :disabled="status === 'loading'" @click="load">
{{ store.getString('count_refresh', 'Refresh count') }}
</button>
</section>
</template>
The example does not gate callApi on hasPermission; the server decides the declared operation. It accepts zero as a real count and rejects numeric strings, missing totals, negative/fractional/non-finite and unsafe integers. It never renders raw errors or response rows.
The generation counter discards late responses after another load or unmount. Watching the exposed project, bindings, flags and user clears stale state when those runtime values change. This does not cancel the old network request, detect every server-side policy change or replace a host reload after installation/audience changes. A 403/404 is a fixed unavailable state, not a reason to broaden permissions. The Refresh button starts a deliberate read, not an automatic retry loop.
3. Expose configurable text and review output
Declare the count_* keys used above in manifest strings.default, and expose supported text customization through the App's normal configuration workflow. The fallback text keeps the example readable when a key is absent; it does not replace proper manifest/configuration review. Use App Configuration and Runtime Strings.
Test with controlled responses: pending load, zero, a positive integer, malformed totals, forbidden/not-found, transport failure, Refresh and a project/context change while an earlier request is pending. Confirm an old result never replaces a newer one and an error never leaves an earlier count visible. The retained component tests compile this exact Vue fence and use a reactive store double; they do not make a real API request or establish installed filtering.
4. Build, install and accept the real release
Run the scaffold's terminating tests/build and inspect actual results. Publish the intended verified variant build, install the explicit version in an approved test project and configure the page audience through Create Your First App and Variants and Releases.
Before calling it complete:
- Record the effective installed version, source/build commit, serving portal/page, principal category and dependency declarations.
- Verify allowed and denied requests on the real endpoint, including a foreign project. Do not log keys or personal response data.
- Inspect the actual network response: the minimal page-principal scalar selection should not include contact fields, but verify other principals, same-model unions and nested resources independently. Merely hiding
datais insufficient. - Compare
meta.totalwith the intended project population;limit: 1must not be mistaken for a total of one. - Check the packaged app after removing any live-session preview overlay, with loading/error/configuration changes and the real audience. Record results in Project Acceptance.
This documentation work creates no App, attendee, page, token or installed release. Real authorization, field privacy, pagination totals, browser/CORS behavior and publication remain environment acceptance steps.