Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions Examples/MistDemo/Sources/MistDemoKit/Resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ <h3>Changes <span class="endpoint-label">zones/changes</span></h3>
</div>
</div>

<!-- Users caller / discover / lookup -->
<!-- Users caller / discover -->
<div class="card pre-auth">
<h2>Users <span class="endpoint-label">users/caller · users/discover · users/lookup/email · users/lookup/id</span></h2>
<h2>Users <span class="endpoint-label">users/caller · users/discover</span></h2>
<div class="panel-grid">
<section>
<h3>Caller <span class="endpoint-label">users/caller</span></h3>
Expand All @@ -258,27 +258,12 @@ <h3>Caller <span class="endpoint-label">users/caller</span></h3>
<pre id="users-caller-raw">(none yet)</pre>
</section>
<section>
<h3>Lookup by Email <span class="endpoint-label">users/lookup/email</span></h3>
<h3>Discover <span class="endpoint-label">users/discover (POST) <em>(CloudKit JS loops per-item)</em></span></h3>
<div class="panel-row">
<input id="users-email-input" type="email" placeholder="user@example.com">
<button id="users-email-btn" type="button">Lookup</button>
<textarea id="users-discover-emails" placeholder="emails, comma-separated"></textarea>
</div>
<div id="users-email-status" class="status"></div>
<pre id="users-email-raw">(none yet)</pre>
</section>
<section>
<h3>Lookup by Record Name <span class="endpoint-label">users/lookup/id</span></h3>
<div class="panel-row">
<input id="users-id-input" type="text" placeholder="userRecordName">
<button id="users-id-btn" type="button">Lookup</button>
</div>
<div id="users-id-status" class="status"></div>
<pre id="users-id-raw">(none yet)</pre>
</section>
<section>
<h3>Discover <span class="endpoint-label">users/discover (POST) <em>(CloudKit JS loops per-email)</em></span></h3>
<div class="panel-row">
<textarea id="users-discover-input" placeholder="one or more emails, comma-separated"></textarea>
<textarea id="users-discover-record-names" placeholder="user record names, comma-separated"></textarea>
<button id="users-discover-btn" type="button">Discover</button>
</div>
<div id="users-discover-status" class="status"></div>
Expand Down
69 changes: 18 additions & 51 deletions Examples/MistDemo/Sources/MistDemoKit/Resources/js/users.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// users/caller · users/discover · users/lookup/email · users/lookup/id
// panel handlers. All four MistKit wrappers landed in #215 but aren't
// exposed on the demo server yet; CloudKit JS fully exercises every
// endpoint today.
// users/caller · users/discover panel handlers. The deprecated
// users/lookup/email and users/lookup/id primitives are not exposed —
// users/discover is Apple's supported replacement and handles both email
// and record-name lookups (phone-number support tracked in #398).

const usersCallerStatus = document.getElementById('users-caller-status');
const usersCallerRaw = document.getElementById('users-caller-raw');
const usersEmailStatus = document.getElementById('users-email-status');
const usersEmailRaw = document.getElementById('users-email-raw');
const usersIdStatus = document.getElementById('users-id-status');
const usersIdRaw = document.getElementById('users-id-raw');
const usersDiscoverStatus = document.getElementById('users-discover-status');
const usersDiscoverRaw = document.getElementById('users-discover-raw');

Expand All @@ -26,48 +22,11 @@ document.getElementById('users-caller-btn').addEventListener('click', async () =
});
});

document.getElementById('users-email-btn').addEventListener('click', async () => {
const email = document.getElementById('users-email-input').value.trim();
if (!email) {
setStatus(usersEmailStatus, 'Provide an email address.', 'error');
return;
}
await runPanelOperation({
statusEl: usersEmailStatus,
rawEl: usersEmailRaw,
label: 'Lookup by email',
fn: async () => {
if (currentMode === 'mistkit') {
return await postJSON('/api/users/lookup/email', { emails: [email] });
}
return await ckJsContainer().discoverUserIdentityWithEmailAddress(email);
},
});
});

document.getElementById('users-id-btn').addEventListener('click', async () => {
const recordName = document.getElementById('users-id-input').value.trim();
if (!recordName) {
setStatus(usersIdStatus, 'Provide a user record name.', 'error');
return;
}
await runPanelOperation({
statusEl: usersIdStatus,
rawEl: usersIdRaw,
label: 'Lookup by record name',
fn: async () => {
if (currentMode === 'mistkit') {
return await postJSON('/api/users/lookup/id', { userRecordNames: [recordName] });
}
return await ckJsContainer().discoverUserIdentityWithUserRecordName(recordName);
},
});
});

document.getElementById('users-discover-btn').addEventListener('click', async () => {
const emails = csv(document.getElementById('users-discover-input').value);
if (emails.length === 0) {
setStatus(usersDiscoverStatus, 'Provide at least one email.', 'error');
const emails = csv(document.getElementById('users-discover-emails').value);
const userRecordNames = csv(document.getElementById('users-discover-record-names').value);
if (emails.length === 0 && userRecordNames.length === 0) {
setStatus(usersDiscoverStatus, 'Provide at least one email or record name.', 'error');
return;
}
await runPanelOperation({
Expand All @@ -76,9 +35,9 @@ document.getElementById('users-discover-btn').addEventListener('click', async ()
label: 'Discover users',
fn: async () => {
if (currentMode === 'mistkit') {
return await postJSON('/api/users/discover', { emails });
return await postJSON('/api/users/discover', { emails, userRecordNames });
}
// CloudKit JS exposes a per-email primitive — loop and aggregate
// CloudKit JS exposes per-item primitives — loop and aggregate
// to match the REST endpoint's batch shape.
const results = [];
for (const email of emails) {
Expand All @@ -89,6 +48,14 @@ document.getElementById('users-discover-btn').addEventListener('click', async ()
results.push({ email, error: error.message });
}
}
for (const recordName of userRecordNames) {
try {
const identity = await ckJsContainer().discoverUserIdentityWithUserRecordName(recordName);
results.push({ userRecordName: recordName, identity });
} catch (error) {
results.push({ userRecordName: recordName, error: error.message });
}
}
return { discovered: results };
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// CloudKitService+WebBackend+Reads.swift
// MistDemo
//
// Created by Leo Dion.
// Copyright © 2026 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

internal import Foundation
internal import MistKit

// Read-side `WebBackend` conformance for records and zones: lookup, changes,
// and zone listing. The primary conformance declaration lives in
// `CloudKitService+WebBackend.swift`.
extension CloudKitService {
internal func webLookupRecords(
recordNames: [String],
database: MistKit.Database
) async throws -> [RecordInfo] {
let results = try await lookupRecords(
recordNames: recordNames,
desiredKeys: nil,
database: database
)
// All-or-nothing: `lookupRecords` returns a per-record `[RecordResult]`,
// but the demo collapses it — any single failure (e.g. CloudKit's
// NOT_FOUND) throws, so the web panel shows the error rather than
// silently returning fewer rows than were asked for. Surfacing partial
// results (found records alongside per-record failures) is a possible
// future enhancement.
return try results.map { try $0.get() }
}

internal func webRecordChanges(
zoneName: String?,
syncToken: String?,
database: MistKit.Database
) async throws -> RecordChangesResult {
try await fetchRecordChanges(
zoneID: zoneName.map { ZoneID(zoneName: $0) },
syncToken: syncToken,
database: database
)
}

internal func webListZones(
database: MistKit.Database
) async throws -> [ZoneInfo] {
try await listZones(database: database)
}

internal func webLookupZones(
zoneNames: [String],
database: MistKit.Database
) async throws -> [ZoneInfo] {
try await lookupZones(
zoneIDs: zoneNames.map { ZoneID(zoneName: $0) },
database: database
)
}

internal func webZoneChanges(
syncToken: String?,
database: MistKit.Database
) async throws -> ZoneChangesResult {
try await fetchZoneChanges(syncToken: syncToken, database: database)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// CloudKitService+WebBackend+Users.swift
// MistDemo
//
// Created by Leo Dion.
// Copyright © 2026 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

internal import Foundation
internal import MistKit

// User-identity `WebBackend` conformance. These operate on the public
// database with web-auth credentials, so none take a `database` argument.
// The primary conformance declaration lives in
// `CloudKitService+WebBackend.swift`.
extension CloudKitService {
internal func webFetchCaller() async throws -> UserInfo {
try await fetchCaller()
}

internal func webDiscoverUsers(
emails: [String],
userRecordNames: [String]
) async throws -> [UserIdentity] {
let lookupInfos =
emails.map { UserIdentityLookupInfo(emailAddress: $0) }
+ userRecordNames.map { UserIdentityLookupInfo(userRecordName: $0) }
return try await discoverUserIdentities(lookupInfos: lookupInfos)
}
}
32 changes: 32 additions & 0 deletions Examples/MistDemo/Sources/MistDemoKit/Server/WebBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,44 @@ internal protocol WebBackend: Sendable {
database: MistKit.Database
) async throws

func webLookupRecords(
recordNames: [String],
database: MistKit.Database
) async throws -> [RecordInfo]

func webRecordChanges(
zoneName: String?,
syncToken: String?,
database: MistKit.Database
) async throws -> RecordChangesResult

func webModifyZones(
create: [String],
delete: [String],
database: MistKit.Database
) async throws -> [ZoneInfo]

func webListZones(
database: MistKit.Database
) async throws -> [ZoneInfo]

func webLookupZones(
zoneNames: [String],
database: MistKit.Database
) async throws -> [ZoneInfo]

func webZoneChanges(
syncToken: String?,
database: MistKit.Database
) async throws -> ZoneChangesResult

func webFetchCaller() async throws -> UserInfo

func webDiscoverUsers(
emails: [String],
userRecordNames: [String]
) async throws -> [UserIdentity]

func webListSubscriptions(
database: MistKit.Database
) async throws -> [SubscriptionInfo]
Expand Down
Loading
Loading