Revision control
Copy as Markdown
// This file was autogenerated by some hot garbage in the `uniffi` crate.
// Trust me, you don't want to mess with it!
// swiftlint:disable all
import Foundation
// Depending on the consumer's build setup, the low-level FFI code
// might be in a separate module, or it might be compiled inline into
// this module. This is a bit of light hackery to work with both.
#if canImport(MozillaRustComponents)
import MozillaRustComponents
#endif
fileprivate extension RustBuffer {
// Allocate a new buffer, copying the contents of a `UInt8` array.
init(bytes: [UInt8]) {
let rbuf = bytes.withUnsafeBufferPointer { ptr in
RustBuffer.from(ptr)
}
self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
}
static func empty() -> RustBuffer {
RustBuffer(capacity: 0, len:0, data: nil)
}
static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
try! rustCall { ffi_fxa_client_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
}
// Frees the buffer in place.
// The buffer must not be used after this is called.
func deallocate() {
try! rustCall { ffi_fxa_client_rustbuffer_free(self, $0) }
}
}
fileprivate extension ForeignBytes {
init(bufferPointer: UnsafeBufferPointer<UInt8>) {
self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
}
init(rawBufferPointer: UnsafeRawBufferPointer) {
self.init(
len: Int32(rawBufferPointer.count),
data: rawBufferPointer.baseAddress?.assumingMemoryBound(to: UInt8.self)
)
}
}
// Converter for `&[u8]` / `[ByRef] bytes` arguments.
//
// Conforms to `FfiConverter` so the compiler enforces the full converter
// method set. Only the scope-bound `lower(_:_body:)` overload is sound —
// zero-copy byte buffers only flow foreign -> Rust, and only in argument
// position. The four protocol-witness methods (`lift`, `lower`, `read`,
// `write`) `fatalError` at runtime if anyone reaches them.
//
// The scope-bound `lower` takes a closure because the `ForeignBytes`
// pointer is only guaranteed valid for the duration of
// `Data.withUnsafeBytes`. Callers must run the full FFI call inside
// the closure body.
fileprivate enum FfiConverterByRefBytes: FfiConverter {
typealias SwiftType = Data
typealias FfiType = ForeignBytes
static func lower<R>(_ value: Data, _ body: (ForeignBytes) throws -> R) rethrows -> R {
return try value.withUnsafeBytes { rawBuf in
try body(ForeignBytes(rawBufferPointer: rawBuf))
}
}
static func lower(_ value: Data) -> ForeignBytes {
fatalError("ByRef bytes cannot use the plain lower: returning ForeignBytes escapes the Data.withUnsafeBytes scope. Use the scope-bound lower(_:_body:) overload instead.")
}
static func lift(_ value: ForeignBytes) throws -> Data {
fatalError("ByRef bytes cannot be lifted: zero-copy &[u8] only flows foreign->Rust")
}
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
fatalError("ByRef bytes cannot be read from a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
}
static func write(_ value: Data, into buf: inout [UInt8]) {
fatalError("ByRef bytes cannot be written to a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
}
}
// For every type used in the interface, we provide helper methods for conveniently
// lifting and lowering that type from C-compatible data, and for reading and writing
// values of that type in a buffer.
// Helper classes/extensions that don't change.
// Someday, this will be in a library of its own.
fileprivate extension Data {
init(rustBuffer: RustBuffer) {
self.init(
bytesNoCopy: rustBuffer.data!,
count: Int(rustBuffer.len),
deallocator: .none
)
}
}
// Define reader functionality. Normally this would be defined in a class or
// struct, but we use standalone functions instead in order to make external
// types work.
//
// With external types, one swift source file needs to be able to call the read
// method on another source file's FfiConverter, but then what visibility
// should Reader have?
// - If Reader is fileprivate, then this means the read() must also
// be fileprivate, which doesn't work with external types.
// - If Reader is internal/public, we'll get compile errors since both source
// files will try define the same type.
//
// Instead, the read() method and these helper functions input a tuple of data
fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
(data: data, offset: 0)
}
// Reads an integer at the current offset, in big-endian order, and advances
// the offset on success. Throws if reading the integer would move the
// offset past the end of the buffer.
fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
let range = reader.offset..<reader.offset + MemoryLayout<T>.size
guard reader.data.count >= range.upperBound else {
throw UniffiInternalError.bufferOverflow
}
if T.self == UInt8.self {
let value = reader.data[reader.offset]
reader.offset += 1
return value as! T
}
var value: T = 0
let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
reader.offset = range.upperBound
return value.bigEndian
}
// Reads an arbitrary number of bytes, to be used to read
// raw bytes, this is useful when lifting strings
fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
let range = reader.offset..<(reader.offset+count)
guard reader.data.count >= range.upperBound else {
throw UniffiInternalError.bufferOverflow
}
var value = [UInt8](repeating: 0, count: count)
value.withUnsafeMutableBufferPointer({ buffer in
reader.data.copyBytes(to: buffer, from: range)
})
reader.offset = range.upperBound
return value
}
// Reads a float at the current offset.
fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
return Float(bitPattern: try readInt(&reader))
}
// Reads a float at the current offset.
fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
return Double(bitPattern: try readInt(&reader))
}
// Indicates if the offset has reached the end of the buffer.
fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
return reader.offset < reader.data.count
}
// Define writer functionality. Normally this would be defined in a class or
// struct, but we use standalone functions instead in order to make external
// types work. See the above discussion on Readers for details.
fileprivate func createWriter() -> [UInt8] {
return []
}
fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
writer.append(contentsOf: byteArr)
}
// Writes an integer in big-endian order.
//
// Warning: make sure what you are trying to write
// is in the correct type!
fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
var value = value.bigEndian
withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
}
fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
writeInt(&writer, value.bitPattern)
}
fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
writeInt(&writer, value.bitPattern)
}
// Protocol for types that transfer other types across the FFI. This is
// analogous to the Rust trait of the same name.
fileprivate protocol FfiConverter {
associatedtype FfiType
associatedtype SwiftType
static func lift(_ value: FfiType) throws -> SwiftType
static func lower(_ value: SwiftType) -> FfiType
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
static func write(_ value: SwiftType, into buf: inout [UInt8])
}
// Types conforming to `Primitive` pass themselves directly over the FFI.
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
extension FfiConverterPrimitive {
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lift(_ value: FfiType) throws -> SwiftType {
return value
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lower(_ value: SwiftType) -> FfiType {
return value
}
}
// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
// Used for complex types where it's hard to write a custom lift/lower.
fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
extension FfiConverterRustBuffer {
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lift(_ buf: RustBuffer) throws -> SwiftType {
var reader = createReader(data: Data(rustBuffer: buf))
let value = try read(from: &reader)
if hasRemaining(reader) {
throw UniffiInternalError.incompleteData
}
buf.deallocate()
return value
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public static func lower(_ value: SwiftType) -> RustBuffer {
var writer = createWriter()
write(value, into: &writer)
return RustBuffer(bytes: writer)
}
}
// An error type for FFI errors. These errors occur at the UniFFI level, not
// the library level.
fileprivate enum UniffiInternalError: LocalizedError {
case bufferOverflow
case incompleteData
case unexpectedOptionalTag
case unexpectedEnumCase
case unexpectedNullPointer
case unexpectedRustCallStatusCode
case unexpectedRustCallError
case unexpectedStaleHandle
case rustPanic(_ message: String)
public var errorDescription: String? {
switch self {
case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
case .incompleteData: return "The buffer still has data after lifting its containing value"
case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
case .unexpectedNullPointer: return "Raw pointer value was null"
case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
case let .rustPanic(message): return message
}
}
}
fileprivate extension NSLock {
func withLock<T>(f: () throws -> T) rethrows -> T {
self.lock()
defer { self.unlock() }
return try f()
}
}
fileprivate let CALL_SUCCESS: Int8 = 0
fileprivate let CALL_ERROR: Int8 = 1
fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
fileprivate let CALL_CANCELLED: Int8 = 3
fileprivate extension RustCallStatus {
init() {
self.init(
code: CALL_SUCCESS,
errorBuf: RustBuffer.init(
capacity: 0,
len: 0,
data: nil
)
)
}
}
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
let neverThrow: ((RustBuffer) throws -> Never)? = nil
return try makeRustCall(callback, errorHandler: neverThrow)
}
private func rustCallWithError<T, E: Swift.Error>(
_ errorHandler: @escaping (RustBuffer) throws -> E,
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
try makeRustCall(callback, errorHandler: errorHandler)
}
private func makeRustCall<T, E: Swift.Error>(
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
errorHandler: ((RustBuffer) throws -> E)?
) throws -> T {
uniffiEnsureFxaClientInitialized()
var callStatus = RustCallStatus.init()
let returnedVal = callback(&callStatus)
try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
return returnedVal
}
private func uniffiCheckCallStatus<E: Swift.Error>(
callStatus: RustCallStatus,
errorHandler: ((RustBuffer) throws -> E)?
) throws {
switch callStatus.code {
case CALL_SUCCESS:
return
case CALL_ERROR:
if let errorHandler = errorHandler {
throw try errorHandler(callStatus.errorBuf)
} else {
callStatus.errorBuf.deallocate()
throw UniffiInternalError.unexpectedRustCallError
}
case CALL_UNEXPECTED_ERROR:
// When the rust code sees a panic, it tries to construct a RustBuffer
// with the message. But if that code panics, then it just sends back
// an empty buffer.
if callStatus.errorBuf.len > 0 {
throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
} else {
callStatus.errorBuf.deallocate()
throw UniffiInternalError.rustPanic("Rust panic")
}
case CALL_CANCELLED:
fatalError("Cancellation not supported yet")
default:
throw UniffiInternalError.unexpectedRustCallStatusCode
}
}
private func uniffiTraitInterfaceCall<T>(
callStatus: UnsafeMutablePointer<RustCallStatus>,
makeCall: () throws -> T,
writeReturn: (T) -> ()
) {
do {
try writeReturn(makeCall())
} catch let error {
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
}
}
private func uniffiTraitInterfaceCallWithError<T, E>(
callStatus: UnsafeMutablePointer<RustCallStatus>,
makeCall: () throws -> T,
writeReturn: (T) -> (),
lowerError: (E) -> RustBuffer
) {
do {
try writeReturn(makeCall())
} catch let error as E {
callStatus.pointee.code = CALL_ERROR
callStatus.pointee.errorBuf = lowerError(error)
} catch {
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
}
}
// Initial value and increment amount for handles.
// These ensure that SWIFT handles always have the lowest bit set
fileprivate let UNIFFI_HANDLEMAP_INITIAL: UInt64 = 1
fileprivate let UNIFFI_HANDLEMAP_DELTA: UInt64 = 2
fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
// All mutation happens with this lock held, which is why we implement @unchecked Sendable.
private let lock = NSLock()
private var map: [UInt64: T] = [:]
private var currentHandle: UInt64 = UNIFFI_HANDLEMAP_INITIAL
func insert(obj: T) -> UInt64 {
lock.withLock {
return doInsert(obj)
}
}
// Low-level insert function, this assumes `lock` is held.
private func doInsert(_ obj: T) -> UInt64 {
let handle = currentHandle
currentHandle += UNIFFI_HANDLEMAP_DELTA
map[handle] = obj
return handle
}
func get(handle: UInt64) throws -> T {
try lock.withLock {
guard let obj = map[handle] else {
throw UniffiInternalError.unexpectedStaleHandle
}
return obj
}
}
func clone(handle: UInt64) throws -> UInt64 {
try lock.withLock {
guard let obj = map[handle] else {
throw UniffiInternalError.unexpectedStaleHandle
}
return doInsert(obj)
}
}
@discardableResult
func remove(handle: UInt64) throws -> T {
try lock.withLock {
guard let obj = map.removeValue(forKey: handle) else {
throw UniffiInternalError.unexpectedStaleHandle
}
return obj
}
}
var count: Int {
get {
map.count
}
}
}
// Public interface members begin here.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterInt64: FfiConverterPrimitive {
typealias FfiType = Int64
typealias SwiftType = Int64
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int64 {
return try lift(readInt(&buf))
}
public static func write(_ value: Int64, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterBool : FfiConverter {
typealias FfiType = Int8
typealias SwiftType = Bool
public static func lift(_ value: Int8) throws -> Bool {
return value != 0
}
public static func lower(_ value: Bool) -> Int8 {
return value ? 1 : 0
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
return try lift(readInt(&buf))
}
public static func write(_ value: Bool, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterString: FfiConverter {
typealias SwiftType = String
typealias FfiType = RustBuffer
public static func lift(_ value: RustBuffer) throws -> String {
defer {
value.deallocate()
}
if value.data == nil {
return String()
}
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
// Use Swift's native UTF-8 decoder; `String(bytes:encoding:.utf8)` goes
// through Foundation's NSString and silently strips a leading U+FEFF BOM.
// Invalid UTF-8 substitutes U+FFFD instead of trapping (unreachable
// given Rust's `String` invariant).
return String(decoding: bytes, as: UTF8.self)
}
public static func lower(_ value: String) -> RustBuffer {
return value.utf8CString.withUnsafeBufferPointer { ptr in
// The swift string gives us int8_t, we want uint8_t.
ptr.withMemoryRebound(to: UInt8.self) { ptr in
// The swift string gives us a trailing null byte, we don't want it.
let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
return RustBuffer.from(buf)
}
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
let len: Int32 = try readInt(&buf)
// See `lift` above for why we avoid Foundation's NSString-backed decoder here.
return String(decoding: try readBytes(&buf, count: Int(len)), as: UTF8.self)
}
public static func write(_ value: String, into buf: inout [UInt8]) {
let len = Int32(value.utf8.count)
writeInt(&buf, len)
writeBytes(&buf, value.utf8)
}
}
/**
* Object representing the signed-in state of an application.
*
* The `FirefoxAccount` object is the main interface provided by this crate.
* It represents the signed-in state of an application that may be connected to
* user's Firefox Account, and provides methods for inspecting the state of the
* account and accessing other services on behalf of the user.
*/
public protocol FirefoxAccountProtocol: AnyObject, Sendable {
/**
* Used by the application to test auth token issues
*/
func simulateNetworkError()
/**
* Get a URL which shows a "successfully connected!" message.
*
* **💾 This method alters the persisted account state.**
*
* Applications can use this method after a successful signin, to redirect the
* user to a success message displayed in web content rather than having to
* implement their own native success UI.
*/
func getConnectionSuccessUrl() throws -> String
/**
* Get a URL at which the user can manage their account and profile data.
*
* **💾 This method alters the persisted account state.**
*
* Applications should link the user out to this URL from an appropriate place
* in their signed-in settings UI.
*
* # Arguments
*
* - `entrypoint` - metrics identifier for UX entrypoint.
* - This parameter is used for metrics purposes, to identify the
* UX entrypoint from which the user followed the link.
*/
func getManageAccountUrl(entrypoint: String) throws -> String
/**
* Get a URL at which the user can manage the devices connected to their account.
*
* **💾 This method alters the persisted account state.**
*
* Applications should link the user out to this URL from an appropriate place
* in their signed-in settings UI. For example, "Manage your devices..." may be
* a useful link to place somewhere near the device list in the send-tab UI.
*
* # Arguments
*
* - `entrypoint` - metrics identifier for UX entrypoint.
* - This parameter is used for metrics purposes, to identify the
* UX entrypoint from which the user followed the link.
*/
func getManageDevicesUrl(entrypoint: String) throws -> String
/**
* Get the token server URL
*
* The token server URL can be used to get the URL and access token for the user's sync data.
*/
func getTokenServerEndpointUrl() throws -> String
/**
* Check if an account was created from a config
*/
func matchesServer(server: FxaServer) throws -> Bool
/**
* Check authorization status for this application.
*
* **💾 This method alters the persisted account state.**
*
* Applications may call this method to check with the FxA server about the status
* of their authentication tokens. It returns an [`AuthorizationInfo`] struct
* with details about whether the tokens are still active.
*/
func checkAuthorizationStatus() throws -> AuthorizationInfo
/**
* Disconnect from the user's account.
*
* **💾 This method alters the persisted account state.**
*
* This method destroys any tokens held by the client, effectively disconnecting
* from the user's account. Applications should call this when the user opts to
* sign out.
*
* The persisted account state after calling this method will contain only the
* user's last-seen profile information, if any. This may be useful in helping
* the user to reconnect to their account. If reconnecting to the same account
* is not desired then the application should discard the persisted account state.
*/
func disconnect()
/**
* Get the URL at which to begin a device-pairing signin flow.
*
* If the user wants to sign in using device pairing, call this method and then
* direct them to visit the resulting URL on an already-signed-in device. Doing
* so will trigger the other device to show a QR code to be scanned, and the result
* from said QR code can be passed to the [`FxaEvent::BeginPairingFlow`] event.
*/
func getPairingAuthorityUrl() throws -> String
/**
* Get the current state
*/
func getState() -> FxaState
/**
* Stores the session token from a WebChannel login JSON payload without exposing it
* to the browser layer.
*
* The `json_payload` is the `data` object from the `fxaccounts:login` WebChannel
* command. The session token is extracted and stored internally; callers never hold
* the raw token value.
*
* **💾 This method alters the persisted account state.**
*/
func handleWebChannelLogin(jsonPayload: String) throws
/**
* Update the state based on authentication issues.
*
* **💾 This method alters the persisted account state.**
*
* Call this if you know there's an authentication / authorization issue that requires the
* user to re-authenticated. It transitions the user to the [FxaState.AuthIssues] state.
*/
func onAuthIssues()
/**
* Process an event (login, logout, etc).
*
* On success, returns the new state.
* On error, the state will remain the same.
*/
func processEvent(event: FxaEvent) throws -> FxaState
/**
* Reset the timer indicating time since last auth issues were encountered.
*
* **💾 This method alters the persisted account state.**
*
* Call this if we have encountered the [FxaState.AuthIssues] state as a result of a
* failure happening (i.e. not as a result of initialization simply loading that state from a
* previous failure).
* Most likely, this should not need to be called externally except in testing since the state
* machine's `transition` function should generally call the internal version of this function
* when necessary.
*/
func resetAuthRecheckTimer()
/**
* Used by the application to test auth token issues
*/
func simulatePermanentAuthTokenIssue()
/**
* Used by the application to test auth token issues
*/
func simulateTemporaryAuthTokenIssue()
/**
* Clear any custom display name used for this application instance.
*
* **💾 This method alters the persisted account state.**
*
* This method clears the name of the current application's device record, causing other
* applications or the user's account management pages to have to fill in some sort of
* default name when displaying this device.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
func clearDeviceName() throws
/**
* Ensure that the device record has a specific set of capabilities.
*
* **💾 This method alters the persisted account state.**
*
* This method checks that the currently-registered device record is advertising the
* given set of capabilities in the FxA "device commands" ecosystem. If not, then it
* updates the device record to do so.
*
* Applications should call this method on each startup as a way to ensure that their
* expected set of capabilities is being accurately reflected on the FxA server, and
* to handle the rollout of new capabilities over time.
*
* # Arguments
*
* - `supported_capabilities` - the set of [capabilities](DeviceCapability) to register
* for this device in the "device commands" ecosystem.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
func ensureCapabilities(supportedCapabilities: [DeviceCapability]) throws -> LocalDevice
/**
* Get the list of all client applications attached to the user's account.
*
* This method returns a list of [`AttachedClient`] structs representing all the applications
* connected to the user's account. This includes applications that are registered as a device
* as well as server-side services that the user has connected.
*
* It will only return active sessions.
* For example, if a user has disconnected the service from their account,
* it wouldn't appear in this list.
*/
func getAttachedClients() throws -> [AttachedClient]
/**
* Get the device id registered for this application.
*
* # Notes
*
* - If the application has not registered a device record, this method will
* throw an [`Other`](FxaError::Other) error.
* - (Yeah...sorry. This should be changed to do something better.)
* - Device metadata is only visible to applications that have been
*/
func getCurrentDeviceId() throws -> String
/**
* Get the list of devices registered on the user's account.
*
* **💾 This method alters the persisted account state.**
*
* This method returns a list of [`Device`] structs representing all the devices
* currently attached to the user's account (including the current device).
* The application might use this information to e.g. display a list of appropriate
* send-tab targets.
*
* # Arguments
*
* - `ignore_cache` - if true, always hit the server for fresh profile information.
*
* # Notes
*
* - Device metadata is only visible to applications that have been
*/
func getDevices(ignoreCache: Bool) throws -> [Device]
/**
* Create a new device record for this application.
*
* **💾 This method alters the persisted account state.**
*
* This method register a device record for the application, providing basic metadata for
* the device along with a list of supported [Device Capabilities](DeviceCapability) for
* participating in the "device commands" ecosystem.
*
* Applications should call this method soon after a successful sign-in, to ensure
* they they appear correctly in the user's account-management pages and when discovered
* by other devices connected to the account.
*
* # Arguments
*
* - `name` - human-readable display name to use for this application
* - `device_type` - the [type](DeviceType) of device the application is installed on
* - `supported_capabilities` - the set of [capabilities](DeviceCapability) to register
* for this device in the "device commands" ecosystem.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
func initializeDevice(name: String, deviceType: DeviceType, supportedCapabilities: [DeviceCapability]) throws -> LocalDevice
/**
* Update the display name used for this application instance.
*
* **💾 This method alters the persisted account state.**
*
* This method modifies the name of the current application's device record, as seen by
* other applications and in the user's account management pages.
*
* # Arguments
*
* - `display_name` - the new name for the current device.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
func setDeviceName(displayName: String) throws -> LocalDevice
/**
* Get profile information for the signed-in user, if any.
*
* **💾 This method alters the persisted account state.**
*
* This method fetches a [`Profile`] struct with information about the currently-signed-in
* user, either by using locally-cached profile information or by fetching fresh data from
* the server.
*
* # Arguments
*
* - `ignore_cache` - if true, always hit the server for fresh profile information.
*
* # Notes
*
* - Profile information is only available to applications that have been
* granted the `profile` scope.
* - There is currently no API for fetching cached profile information without
* potentially hitting the server.
* - If there is no signed-in user, this method will throw an
* [`Authentication`](FxaError::Authentication) error.
*/
func getProfile(ignoreCache: Bool) throws -> Profile
/**
* Use device commands to close one or more tabs on another device.
*
* **💾 This method alters the persisted account state.**
*
* If a device on the account has registered the [`CloseTabs`](DeviceCapability::CloseTabs)
* capability, this method can be used to close its tabs.
*/
func closeTabs(targetDeviceId: String, urls: [String]) throws -> CloseTabsResult
/**
* Process and respond to a server-delivered account update message
*
* **💾 This method alters the persisted account state.**
*
* Applications should call this method whenever they receive a push notification from the Firefox Accounts server.
* Such messages typically indicate a noteworthy change of state on the user's account, such as an update to their profile information
* or the disconnection of a client. The [`FirefoxAccount`] struct will update its internal state
* accordingly and return an individual [`AccountEvent`] struct describing the event, which the application
* may use for further processing.
*
* It's important to note if the event is [`AccountEvent::CommandReceived`], the caller should call
* [`FirefoxAccount::poll_device_commands`]
*/
func handlePushMessage(payload: String) throws -> AccountEvent
/**
* Poll the server for any pending device commands.
*
* **💾 This method alters the persisted account state.**
*
* Applications that have registered one or more [`DeviceCapability`]s with the server can use
* this method to check whether other devices on the account have sent them any commands.
* It will return a list of [`IncomingDeviceCommand`] structs for the application to process.
*
* # Notes
*
* - Device commands are typically delivered via push message and the [`CommandReceived`](
* AccountEvent::CommandReceived) event. Polling should only be used as a backup delivery
* mechanism, f the application has reason to believe that push messages may have been missed.
* - Device commands functionality is only available to applications that have been
*/
func pollDeviceCommands() throws -> [IncomingDeviceCommand]
/**
* Use device commands to send a single tab to another device.
*
* **💾 This method alters the persisted account state.**
*
* If a device on the account has registered the [`SendTab`](DeviceCapability::SendTab)
* capability, this method can be used to send it a tab.
*
* # Notes
*
* - If the given device id does not existing or is not capable of receiving tabs,
* this method will throw an [`Other`](FxaError::Other) error.
* - (Yeah...sorry. This should be changed to do something better.)
* - It is not currently possible to send a full [`SendTabPayload`] to another device,
* but that's purely an API limitation that should go away in future.
* - Device commands functionality is only available to applications that have been
*/
func sendSingleTab(targetDeviceId: String, title: String, url: String, isPrivate: Bool) throws
/**
* Set or update a push subscription endpoint for this device.
*
* **💾 This method alters the persisted account state.**
*
* This method registers the given webpush subscription with the FxA server, requesting
* that is send notifications in the event of any significant changes to the user's
* account. When the application receives a push message at the registered subscription
* endpoint, it should decrypt the payload and pass it to the [`handle_push_message`](
* FirefoxAccount::handle_push_message) method for processing.
*
* # Arguments
*
* - `subscription` - the [`DevicePushSubscription`] details to register with the server.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
func setPushSubscription(subscription: DevicePushSubscription) throws -> LocalDevice
/**
* Save current state to a JSON string.
*
* This method serializes the current account state into a JSON string, which
* the application can use to persist the user's signed-in state across restarts.
* The application should call this method and update its persisted state after
* any potentially-state-changing operation.
*
* **⚠️ Warning:** the serialized state may contain encryption keys and access
* tokens that let anyone holding them access the user's data in Firefox Sync
* and/or other FxA services. Applications should take care to store the resulting
* data in a secure fashion, as appropriate for their target platform.
*/
func toJson() throws -> String
/**
* Collect and return telemetry about send-tab attempts.
*
* Applications that register the [`SendTab`](DeviceCapability::SendTab) capability
* should also arrange to submit "sync ping" telemetry. Calling this method will
* return a JSON string of telemetry data that can be incorporated into that ping.
*
* Sorry, this is not particularly carefully documented because it is intended
* as a stop-gap until we get native Glean support. If you know how to submit
* a sync ping, you'll know what to do with the contents of the JSON string.
*/
func gatherTelemetry() throws -> String
/**
* Create a new OAuth authorization code using the stored session token.
*
* When a signed-in application receives an incoming device pairing request, it can
* use this method to grant the request and generate a corresponding OAuth authorization
* code. This code would then be passed back to the connecting device over the
* pairing channel (a process which is not currently supported by any code in this
* component).
*
* # Arguments
*
* - `params` - the OAuth parameters from the incoming authorization request
*/
func authorizeCodeUsingSessionToken(params: AuthorizationParameters) throws -> String
/**
* Clear the access token cache in response to an auth failure.
*
* **💾 This method alters the persisted account state.**
*
* Applications that receive an authentication error when trying to use an access token,
* should call this method before creating a new token and retrying the failed operation.
* It ensures that the expired token is removed and a fresh one generated.
*/
func clearAccessTokenCache()
/**
* Get a short-lived OAuth access token for the user's account.
*
* **💾 This method alters the persisted account state.**
*
* Applications that need to access resources on behalf of the user must obtain an
* `access_token` in order to do so. For example, an access token is required when
* fetching the user's profile data, or when accessing their data stored in Firefox Sync.
*
* This method will obtain and return an access token bearing the requested scopes, either
* from a local cache of previously-issued tokens, or by creating a new one from the server.
*
* # Arguments
*
* - `scope` - space-separated list of OAuth scopes to be granted by the token.
* - Each scope must have been requested during the signin flow, or be a scope
* which the server might offer automatically in some account-specific cases.
* - Scope order is not significant; `"a b"` and `"b a"` are equivalent.
* - When a single scope is requested and it has an associated scoped key
* `AccessTokenInfo::key` will be populated; for multi-scope requests it is `None`.
* - `use_cache` - optionally set to false to force a new token request. The fetched
* token will still be cached for later `get_access_token` calls.
*
* # Notes
*
* - If the application receives an authorization error when trying to use the resulting
* token, it should call [`clear_access_token_cache`](FirefoxAccount::clear_access_token_cache)
* before requesting a fresh token.
*/
func getAccessToken(scope: String, useCache: Bool) throws -> AccessTokenInfo
/**
* Get the session token for the user's account, if one is available.
*
* **💾 This method alters the persisted account state.**
*
* Applications that function as a web browser may need to hold on to a session token
* on behalf of Firefox Accounts web content. This method exists so that they can retrieve
* it an pass it back to said web content when required.
*
* # Notes
*
* - Please do not attempt to use the resulting token to directly make calls to the
* Firefox Accounts servers! All account management functionality should be performed
* in web content.
* - A session token is only available to applications that have requested the
*/
func getSessionToken() throws -> String
/**
* Builds a complete `signedInUser` JSON object for a WebChannel `fxaccounts:fxa_status`
* response, embedding the session token without exposing it to the browser layer. Email and
* uid are read from the cached profile in internal state. Returns `None` if no session token
* is available.
*/
func getSignedInUserForWebChannel() -> String?
/**
* Update the stored session token for the user's account.
*
* **💾 This method alters the persisted account state.**
*
* Applications that function as a web browser may need to hold on to a session token
* on behalf of Firefox Accounts web content. This method exists so that said web content
* signals that it has generated a new session token, the stored value can be updated
* to match.
*
* # Arguments
*
* - `session_token` - the new session token value provided from web content.
*/
func handleSessionTokenChange(sessionToken: String) throws
/**
* Handle a WebChannel password-change notification by exchanging the new session token
* for a new refresh token.
*
* **💾 This method alters the persisted account state.**
*/
func handleWebChannelPasswordChange(jsonPayload: String) throws
/**
* Check whether the account has already been granted the given OAuth scope(s).
*
* This checks whether the refresh token has *every* specified scope.
*
* # Arguments
* - `scope` - space-separated list of OAuth scopes. Order is not significant.
*/
func hasScope(scope: String) -> Bool
}
/**
* Object representing the signed-in state of an application.
*
* The `FirefoxAccount` object is the main interface provided by this crate.
* It represents the signed-in state of an application that may be connected to
* user's Firefox Account, and provides methods for inspecting the state of the
* account and accessing other services on behalf of the user.
*/
open class FirefoxAccount: FirefoxAccountProtocol, @unchecked Sendable {
fileprivate let handle: UInt64
/// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct NoHandle {
public init() {}
}
// TODO: We'd like this to be `private` but for Swifty reasons,
// we can't implement `FfiConverter` without making this `required` and we can't
// make it `required` without making it `public`.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
required public init(unsafeFromHandle handle: UInt64) {
self.handle = handle
}
// This constructor can be used to instantiate a fake object.
// - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
//
// - Warning:
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public init(noHandle: NoHandle) {
self.handle = 0
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func uniffiCloneHandle() -> UInt64 {
return try! rustCall { uniffi_fxa_client_fn_clone_firefoxaccount(self.handle, $0) }
}
/**
* Create a new [`FirefoxAccount`] instance, not connected to any account.
*
* **💾 This method alters the persisted account state.**
*
* This method constructs as new [`FirefoxAccount`] instance configured to connect
* the application to a user's account.
*/
public convenience init(config: FxaConfig) {
let handle =
try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_constructor_firefoxaccount_new(
FfiConverterTypeFxaConfig_lower(config),uniffiCallStatus
)
}
self.init(unsafeFromHandle: handle)
}
deinit {
if handle == 0 {
// Mock objects have handle=0 don't try to free them
return
}
try! rustCall { uniffi_fxa_client_fn_free_firefoxaccount(handle, $0) }
}
/**
* Restore a [`FirefoxAccount`] instance from serialized state.
*
* Given a JSON string previously obtained from [`FirefoxAccount::to_json`], this
* method will deserialize it and return a live [`FirefoxAccount`] instance.
*
* **⚠️ Warning:** since the serialized state contains access tokens, you should
* not call `from_json` multiple times on the same data. This would result
* in multiple live objects sharing the same access tokens and is likely to
* produce unexpected behaviour.
*/
public static func fromJson(data: String)throws -> FirefoxAccount {
return try FfiConverterTypeFirefoxAccount_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_constructor_firefoxaccount_from_json(
FfiConverterString.lower(data),uniffiCallStatus
)
})
}
/**
* Used by the application to test auth token issues
*/
open func simulateNetworkError() {try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_simulate_network_error(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Get a URL which shows a "successfully connected!" message.
*
* **💾 This method alters the persisted account state.**
*
* Applications can use this method after a successful signin, to redirect the
* user to a success message displayed in web content rather than having to
* implement their own native success UI.
*/
open func getConnectionSuccessUrl()throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_connection_success_url(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Get a URL at which the user can manage their account and profile data.
*
* **💾 This method alters the persisted account state.**
*
* Applications should link the user out to this URL from an appropriate place
* in their signed-in settings UI.
*
* # Arguments
*
* - `entrypoint` - metrics identifier for UX entrypoint.
* - This parameter is used for metrics purposes, to identify the
* UX entrypoint from which the user followed the link.
*/
open func getManageAccountUrl(entrypoint: String)throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_manage_account_url(
self.uniffiCloneHandle(),
FfiConverterString.lower(entrypoint),uniffiCallStatus
)
})
}
/**
* Get a URL at which the user can manage the devices connected to their account.
*
* **💾 This method alters the persisted account state.**
*
* Applications should link the user out to this URL from an appropriate place
* in their signed-in settings UI. For example, "Manage your devices..." may be
* a useful link to place somewhere near the device list in the send-tab UI.
*
* # Arguments
*
* - `entrypoint` - metrics identifier for UX entrypoint.
* - This parameter is used for metrics purposes, to identify the
* UX entrypoint from which the user followed the link.
*/
open func getManageDevicesUrl(entrypoint: String)throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_manage_devices_url(
self.uniffiCloneHandle(),
FfiConverterString.lower(entrypoint),uniffiCallStatus
)
})
}
/**
* Get the token server URL
*
* The token server URL can be used to get the URL and access token for the user's sync data.
*/
open func getTokenServerEndpointUrl()throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_token_server_endpoint_url(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Check if an account was created from a config
*/
open func matchesServer(server: FxaServer)throws -> Bool {
return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_matches_server(
self.uniffiCloneHandle(),
FfiConverterTypeFxaServer_lower(server),uniffiCallStatus
)
})
}
/**
* Check authorization status for this application.
*
* **💾 This method alters the persisted account state.**
*
* Applications may call this method to check with the FxA server about the status
* of their authentication tokens. It returns an [`AuthorizationInfo`] struct
* with details about whether the tokens are still active.
*/
open func checkAuthorizationStatus()throws -> AuthorizationInfo {
return try FfiConverterTypeAuthorizationInfo_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_check_authorization_status(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Disconnect from the user's account.
*
* **💾 This method alters the persisted account state.**
*
* This method destroys any tokens held by the client, effectively disconnecting
* from the user's account. Applications should call this when the user opts to
* sign out.
*
* The persisted account state after calling this method will contain only the
* user's last-seen profile information, if any. This may be useful in helping
* the user to reconnect to their account. If reconnecting to the same account
* is not desired then the application should discard the persisted account state.
*/
open func disconnect() {try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_disconnect(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Get the URL at which to begin a device-pairing signin flow.
*
* If the user wants to sign in using device pairing, call this method and then
* direct them to visit the resulting URL on an already-signed-in device. Doing
* so will trigger the other device to show a QR code to be scanned, and the result
* from said QR code can be passed to the [`FxaEvent::BeginPairingFlow`] event.
*/
open func getPairingAuthorityUrl()throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_pairing_authority_url(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Get the current state
*/
open func getState() -> FxaState {
return try! FfiConverterTypeFxaState_lift(try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_state(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Stores the session token from a WebChannel login JSON payload without exposing it
* to the browser layer.
*
* The `json_payload` is the `data` object from the `fxaccounts:login` WebChannel
* command. The session token is extracted and stored internally; callers never hold
* the raw token value.
*
* **💾 This method alters the persisted account state.**
*/
open func handleWebChannelLogin(jsonPayload: String)throws {try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_handle_web_channel_login(
self.uniffiCloneHandle(),
FfiConverterString.lower(jsonPayload),uniffiCallStatus
)
}
}
/**
* Update the state based on authentication issues.
*
* **💾 This method alters the persisted account state.**
*
* Call this if you know there's an authentication / authorization issue that requires the
* user to re-authenticated. It transitions the user to the [FxaState.AuthIssues] state.
*/
open func onAuthIssues() {try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_on_auth_issues(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Process an event (login, logout, etc).
*
* On success, returns the new state.
* On error, the state will remain the same.
*/
open func processEvent(event: FxaEvent)throws -> FxaState {
return try FfiConverterTypeFxaState_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_process_event(
self.uniffiCloneHandle(),
FfiConverterTypeFxaEvent_lower(event),uniffiCallStatus
)
})
}
/**
* Reset the timer indicating time since last auth issues were encountered.
*
* **💾 This method alters the persisted account state.**
*
* Call this if we have encountered the [FxaState.AuthIssues] state as a result of a
* failure happening (i.e. not as a result of initialization simply loading that state from a
* previous failure).
* Most likely, this should not need to be called externally except in testing since the state
* machine's `transition` function should generally call the internal version of this function
* when necessary.
*/
open func resetAuthRecheckTimer() {try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_reset_auth_recheck_timer(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Used by the application to test auth token issues
*/
open func simulatePermanentAuthTokenIssue() {try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_simulate_permanent_auth_token_issue(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Used by the application to test auth token issues
*/
open func simulateTemporaryAuthTokenIssue() {try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_simulate_temporary_auth_token_issue(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Clear any custom display name used for this application instance.
*
* **💾 This method alters the persisted account state.**
*
* This method clears the name of the current application's device record, causing other
* applications or the user's account management pages to have to fill in some sort of
* default name when displaying this device.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
open func clearDeviceName()throws {try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_clear_device_name(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Ensure that the device record has a specific set of capabilities.
*
* **💾 This method alters the persisted account state.**
*
* This method checks that the currently-registered device record is advertising the
* given set of capabilities in the FxA "device commands" ecosystem. If not, then it
* updates the device record to do so.
*
* Applications should call this method on each startup as a way to ensure that their
* expected set of capabilities is being accurately reflected on the FxA server, and
* to handle the rollout of new capabilities over time.
*
* # Arguments
*
* - `supported_capabilities` - the set of [capabilities](DeviceCapability) to register
* for this device in the "device commands" ecosystem.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
open func ensureCapabilities(supportedCapabilities: [DeviceCapability])throws -> LocalDevice {
return try FfiConverterTypeLocalDevice_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_ensure_capabilities(
self.uniffiCloneHandle(),
FfiConverterSequenceTypeDeviceCapability.lower(supportedCapabilities),uniffiCallStatus
)
})
}
/**
* Get the list of all client applications attached to the user's account.
*
* This method returns a list of [`AttachedClient`] structs representing all the applications
* connected to the user's account. This includes applications that are registered as a device
* as well as server-side services that the user has connected.
*
* It will only return active sessions.
* For example, if a user has disconnected the service from their account,
* it wouldn't appear in this list.
*/
open func getAttachedClients()throws -> [AttachedClient] {
return try FfiConverterSequenceTypeAttachedClient.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_attached_clients(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Get the device id registered for this application.
*
* # Notes
*
* - If the application has not registered a device record, this method will
* throw an [`Other`](FxaError::Other) error.
* - (Yeah...sorry. This should be changed to do something better.)
* - Device metadata is only visible to applications that have been
*/
open func getCurrentDeviceId()throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_current_device_id(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Get the list of devices registered on the user's account.
*
* **💾 This method alters the persisted account state.**
*
* This method returns a list of [`Device`] structs representing all the devices
* currently attached to the user's account (including the current device).
* The application might use this information to e.g. display a list of appropriate
* send-tab targets.
*
* # Arguments
*
* - `ignore_cache` - if true, always hit the server for fresh profile information.
*
* # Notes
*
* - Device metadata is only visible to applications that have been
*/
open func getDevices(ignoreCache: Bool)throws -> [Device] {
return try FfiConverterSequenceTypeDevice.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_devices(
self.uniffiCloneHandle(),
FfiConverterBool.lower(ignoreCache),uniffiCallStatus
)
})
}
/**
* Create a new device record for this application.
*
* **💾 This method alters the persisted account state.**
*
* This method register a device record for the application, providing basic metadata for
* the device along with a list of supported [Device Capabilities](DeviceCapability) for
* participating in the "device commands" ecosystem.
*
* Applications should call this method soon after a successful sign-in, to ensure
* they they appear correctly in the user's account-management pages and when discovered
* by other devices connected to the account.
*
* # Arguments
*
* - `name` - human-readable display name to use for this application
* - `device_type` - the [type](DeviceType) of device the application is installed on
* - `supported_capabilities` - the set of [capabilities](DeviceCapability) to register
* for this device in the "device commands" ecosystem.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
open func initializeDevice(name: String, deviceType: DeviceType, supportedCapabilities: [DeviceCapability])throws -> LocalDevice {
return try FfiConverterTypeLocalDevice_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_initialize_device(
self.uniffiCloneHandle(),
FfiConverterString.lower(name),
FfiConverterTypeDeviceType_lower(deviceType),
FfiConverterSequenceTypeDeviceCapability.lower(supportedCapabilities),uniffiCallStatus
)
})
}
/**
* Update the display name used for this application instance.
*
* **💾 This method alters the persisted account state.**
*
* This method modifies the name of the current application's device record, as seen by
* other applications and in the user's account management pages.
*
* # Arguments
*
* - `display_name` - the new name for the current device.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
open func setDeviceName(displayName: String)throws -> LocalDevice {
return try FfiConverterTypeLocalDevice_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_set_device_name(
self.uniffiCloneHandle(),
FfiConverterString.lower(displayName),uniffiCallStatus
)
})
}
/**
* Get profile information for the signed-in user, if any.
*
* **💾 This method alters the persisted account state.**
*
* This method fetches a [`Profile`] struct with information about the currently-signed-in
* user, either by using locally-cached profile information or by fetching fresh data from
* the server.
*
* # Arguments
*
* - `ignore_cache` - if true, always hit the server for fresh profile information.
*
* # Notes
*
* - Profile information is only available to applications that have been
* granted the `profile` scope.
* - There is currently no API for fetching cached profile information without
* potentially hitting the server.
* - If there is no signed-in user, this method will throw an
* [`Authentication`](FxaError::Authentication) error.
*/
open func getProfile(ignoreCache: Bool)throws -> Profile {
return try FfiConverterTypeProfile_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_profile(
self.uniffiCloneHandle(),
FfiConverterBool.lower(ignoreCache),uniffiCallStatus
)
})
}
/**
* Use device commands to close one or more tabs on another device.
*
* **💾 This method alters the persisted account state.**
*
* If a device on the account has registered the [`CloseTabs`](DeviceCapability::CloseTabs)
* capability, this method can be used to close its tabs.
*/
open func closeTabs(targetDeviceId: String, urls: [String])throws -> CloseTabsResult {
return try FfiConverterTypeCloseTabsResult_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_close_tabs(
self.uniffiCloneHandle(),
FfiConverterString.lower(targetDeviceId),
FfiConverterSequenceString.lower(urls),uniffiCallStatus
)
})
}
/**
* Process and respond to a server-delivered account update message
*
* **💾 This method alters the persisted account state.**
*
* Applications should call this method whenever they receive a push notification from the Firefox Accounts server.
* Such messages typically indicate a noteworthy change of state on the user's account, such as an update to their profile information
* or the disconnection of a client. The [`FirefoxAccount`] struct will update its internal state
* accordingly and return an individual [`AccountEvent`] struct describing the event, which the application
* may use for further processing.
*
* It's important to note if the event is [`AccountEvent::CommandReceived`], the caller should call
* [`FirefoxAccount::poll_device_commands`]
*/
open func handlePushMessage(payload: String)throws -> AccountEvent {
return try FfiConverterTypeAccountEvent_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_handle_push_message(
self.uniffiCloneHandle(),
FfiConverterString.lower(payload),uniffiCallStatus
)
})
}
/**
* Poll the server for any pending device commands.
*
* **💾 This method alters the persisted account state.**
*
* Applications that have registered one or more [`DeviceCapability`]s with the server can use
* this method to check whether other devices on the account have sent them any commands.
* It will return a list of [`IncomingDeviceCommand`] structs for the application to process.
*
* # Notes
*
* - Device commands are typically delivered via push message and the [`CommandReceived`](
* AccountEvent::CommandReceived) event. Polling should only be used as a backup delivery
* mechanism, f the application has reason to believe that push messages may have been missed.
* - Device commands functionality is only available to applications that have been
*/
open func pollDeviceCommands()throws -> [IncomingDeviceCommand] {
return try FfiConverterSequenceTypeIncomingDeviceCommand.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_poll_device_commands(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Use device commands to send a single tab to another device.
*
* **💾 This method alters the persisted account state.**
*
* If a device on the account has registered the [`SendTab`](DeviceCapability::SendTab)
* capability, this method can be used to send it a tab.
*
* # Notes
*
* - If the given device id does not existing or is not capable of receiving tabs,
* this method will throw an [`Other`](FxaError::Other) error.
* - (Yeah...sorry. This should be changed to do something better.)
* - It is not currently possible to send a full [`SendTabPayload`] to another device,
* but that's purely an API limitation that should go away in future.
* - Device commands functionality is only available to applications that have been
*/
open func sendSingleTab(targetDeviceId: String, title: String, url: String, isPrivate: Bool = false)throws {try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_send_single_tab(
self.uniffiCloneHandle(),
FfiConverterString.lower(targetDeviceId),
FfiConverterString.lower(title),
FfiConverterString.lower(url),
FfiConverterBool.lower(isPrivate),uniffiCallStatus
)
}
}
/**
* Set or update a push subscription endpoint for this device.
*
* **💾 This method alters the persisted account state.**
*
* This method registers the given webpush subscription with the FxA server, requesting
* that is send notifications in the event of any significant changes to the user's
* account. When the application receives a push message at the registered subscription
* endpoint, it should decrypt the payload and pass it to the [`handle_push_message`](
* FirefoxAccount::handle_push_message) method for processing.
*
* # Arguments
*
* - `subscription` - the [`DevicePushSubscription`] details to register with the server.
*
* # Notes
*
* - Device registration is only available to applications that have been
*/
open func setPushSubscription(subscription: DevicePushSubscription)throws -> LocalDevice {
return try FfiConverterTypeLocalDevice_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_set_push_subscription(
self.uniffiCloneHandle(),
FfiConverterTypeDevicePushSubscription_lower(subscription),uniffiCallStatus
)
})
}
/**
* Save current state to a JSON string.
*
* This method serializes the current account state into a JSON string, which
* the application can use to persist the user's signed-in state across restarts.
* The application should call this method and update its persisted state after
* any potentially-state-changing operation.
*
* **⚠️ Warning:** the serialized state may contain encryption keys and access
* tokens that let anyone holding them access the user's data in Firefox Sync
* and/or other FxA services. Applications should take care to store the resulting
* data in a secure fashion, as appropriate for their target platform.
*/
open func toJson()throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_to_json(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Collect and return telemetry about send-tab attempts.
*
* Applications that register the [`SendTab`](DeviceCapability::SendTab) capability
* should also arrange to submit "sync ping" telemetry. Calling this method will
* return a JSON string of telemetry data that can be incorporated into that ping.
*
* Sorry, this is not particularly carefully documented because it is intended
* as a stop-gap until we get native Glean support. If you know how to submit
* a sync ping, you'll know what to do with the contents of the JSON string.
*/
open func gatherTelemetry()throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_gather_telemetry(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Create a new OAuth authorization code using the stored session token.
*
* When a signed-in application receives an incoming device pairing request, it can
* use this method to grant the request and generate a corresponding OAuth authorization
* code. This code would then be passed back to the connecting device over the
* pairing channel (a process which is not currently supported by any code in this
* component).
*
* # Arguments
*
* - `params` - the OAuth parameters from the incoming authorization request
*/
open func authorizeCodeUsingSessionToken(params: AuthorizationParameters)throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_authorize_code_using_session_token(
self.uniffiCloneHandle(),
FfiConverterTypeAuthorizationParameters_lower(params),uniffiCallStatus
)
})
}
/**
* Clear the access token cache in response to an auth failure.
*
* **💾 This method alters the persisted account state.**
*
* Applications that receive an authentication error when trying to use an access token,
* should call this method before creating a new token and retrying the failed operation.
* It ensures that the expired token is removed and a fresh one generated.
*/
open func clearAccessTokenCache() {try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_clear_access_token_cache(
self.uniffiCloneHandle(),uniffiCallStatus
)
}
}
/**
* Get a short-lived OAuth access token for the user's account.
*
* **💾 This method alters the persisted account state.**
*
* Applications that need to access resources on behalf of the user must obtain an
* `access_token` in order to do so. For example, an access token is required when
* fetching the user's profile data, or when accessing their data stored in Firefox Sync.
*
* This method will obtain and return an access token bearing the requested scopes, either
* from a local cache of previously-issued tokens, or by creating a new one from the server.
*
* # Arguments
*
* - `scope` - space-separated list of OAuth scopes to be granted by the token.
* - Each scope must have been requested during the signin flow, or be a scope
* which the server might offer automatically in some account-specific cases.
* - Scope order is not significant; `"a b"` and `"b a"` are equivalent.
* - When a single scope is requested and it has an associated scoped key
* `AccessTokenInfo::key` will be populated; for multi-scope requests it is `None`.
* - `use_cache` - optionally set to false to force a new token request. The fetched
* token will still be cached for later `get_access_token` calls.
*
* # Notes
*
* - If the application receives an authorization error when trying to use the resulting
* token, it should call [`clear_access_token_cache`](FirefoxAccount::clear_access_token_cache)
* before requesting a fresh token.
*/
open func getAccessToken(scope: String, useCache: Bool = true)throws -> AccessTokenInfo {
return try FfiConverterTypeAccessTokenInfo_lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_access_token(
self.uniffiCloneHandle(),
FfiConverterString.lower(scope),
FfiConverterBool.lower(useCache),uniffiCallStatus
)
})
}
/**
* Get the session token for the user's account, if one is available.
*
* **💾 This method alters the persisted account state.**
*
* Applications that function as a web browser may need to hold on to a session token
* on behalf of Firefox Accounts web content. This method exists so that they can retrieve
* it an pass it back to said web content when required.
*
* # Notes
*
* - Please do not attempt to use the resulting token to directly make calls to the
* Firefox Accounts servers! All account management functionality should be performed
* in web content.
* - A session token is only available to applications that have requested the
*/
open func getSessionToken()throws -> String {
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_session_token(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Builds a complete `signedInUser` JSON object for a WebChannel `fxaccounts:fxa_status`
* response, embedding the session token without exposing it to the browser layer. Email and
* uid are read from the cached profile in internal state. Returns `None` if no session token
* is available.
*/
open func getSignedInUserForWebChannel() -> String? {
return try! FfiConverterOptionString.lift(try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_get_signed_in_user_for_web_channel(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
/**
* Update the stored session token for the user's account.
*
* **💾 This method alters the persisted account state.**
*
* Applications that function as a web browser may need to hold on to a session token
* on behalf of Firefox Accounts web content. This method exists so that said web content
* signals that it has generated a new session token, the stored value can be updated
* to match.
*
* # Arguments
*
* - `session_token` - the new session token value provided from web content.
*/
open func handleSessionTokenChange(sessionToken: String)throws {try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_handle_session_token_change(
self.uniffiCloneHandle(),
FfiConverterString.lower(sessionToken),uniffiCallStatus
)
}
}
/**
* Handle a WebChannel password-change notification by exchanging the new session token
* for a new refresh token.
*
* **💾 This method alters the persisted account state.**
*/
open func handleWebChannelPasswordChange(jsonPayload: String)throws {try rustCallWithError(FfiConverterTypeFxaError_lift) {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_handle_web_channel_password_change(
self.uniffiCloneHandle(),
FfiConverterString.lower(jsonPayload),uniffiCallStatus
)
}
}
/**
* Check whether the account has already been granted the given OAuth scope(s).
*
* This checks whether the refresh token has *every* specified scope.
*
* # Arguments
* - `scope` - space-separated list of OAuth scopes. Order is not significant.
*/
open func hasScope(scope: String) -> Bool {
return try! FfiConverterBool.lift(try! rustCall() {
uniffiCallStatus in
uniffi_fxa_client_fn_method_firefoxaccount_has_scope(
self.uniffiCloneHandle(),
FfiConverterString.lower(scope),uniffiCallStatus
)
})
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFirefoxAccount: FfiConverter {
typealias FfiType = UInt64
typealias SwiftType = FirefoxAccount
public static func lift(_ handle: UInt64) throws -> FirefoxAccount {
return FirefoxAccount(unsafeFromHandle: handle)
}
public static func lower(_ value: FirefoxAccount) -> UInt64 {
return value.uniffiCloneHandle()
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FirefoxAccount {
let handle: UInt64 = try readInt(&buf)
return try lift(handle)
}
public static func write(_ value: FirefoxAccount, into buf: inout [UInt8]) {
writeInt(&buf, lower(value))
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFirefoxAccount_lift(_ handle: UInt64) throws -> FirefoxAccount {
return try FfiConverterTypeFirefoxAccount.lift(handle)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFirefoxAccount_lower(_ value: FirefoxAccount) -> UInt64 {
return FfiConverterTypeFirefoxAccount.lower(value)
}
/**
* An OAuth access token, with its associated keys and metadata.
*
* This struct represents an FxA OAuth access token, which can be used to access a resource
* or service on behalf of the user. For example, accessing the user's data in Firefox Sync
* associated encryption key.
*/
public struct AccessTokenInfo: Equatable, Hashable {
/**
* The scope of access granted by token.
*/
public var scope: String
/**
* The access token itself.
*
* This is the value that should be included in the `Authorization` header when
* accessing an OAuth protected resource on behalf of the user.
*/
public var token: String
/**
* The client-side encryption key associated with this scope.
*
* **⚠️ Warning:** the value of this field should never be revealed outside of the
* application. For example, it should never to sent to a server or logged in a log file.
*/
public var key: ScopedKey?
/**
* The expiry time of the token, in seconds.
*
* This is the timestamp at which the token is set to expire, in seconds since
* unix epoch. Note that it is a signed integer, for compatibility with languages
* that do not have an unsigned integer type.
*
* This timestamp is for guidance only. Access tokens are not guaranteed to remain
* value for any particular lengthof time, and consumers should be prepared to handle
* auth failures even if the token has not yet expired.
*/
public var expiresAt: Int64
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(
/**
* The scope of access granted by token.
*/scope: String,
/**
* The access token itself.
*
* This is the value that should be included in the `Authorization` header when
* accessing an OAuth protected resource on behalf of the user.
*/token: String,
/**
* The client-side encryption key associated with this scope.
*
* **⚠️ Warning:** the value of this field should never be revealed outside of the
* application. For example, it should never to sent to a server or logged in a log file.
*/key: ScopedKey?,
/**
* The expiry time of the token, in seconds.
*
* This is the timestamp at which the token is set to expire, in seconds since
* unix epoch. Note that it is a signed integer, for compatibility with languages
* that do not have an unsigned integer type.
*
* This timestamp is for guidance only. Access tokens are not guaranteed to remain
* value for any particular lengthof time, and consumers should be prepared to handle
* auth failures even if the token has not yet expired.
*/expiresAt: Int64) {
self.scope = scope
self.token = token
self.key = key
self.expiresAt = expiresAt
}
}
#if compiler(>=6)
extension AccessTokenInfo: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeAccessTokenInfo: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AccessTokenInfo {
return
try AccessTokenInfo(
scope: FfiConverterString.read(from: &buf),
token: FfiConverterString.read(from: &buf),
key: FfiConverterOptionTypeScopedKey.read(from: &buf),
expiresAt: FfiConverterInt64.read(from: &buf)
)
}
public static func write(_ value: AccessTokenInfo, into buf: inout [UInt8]) {
FfiConverterString.write(value.scope, into: &buf)
FfiConverterString.write(value.token, into: &buf)
FfiConverterOptionTypeScopedKey.write(value.key, into: &buf)
FfiConverterInt64.write(value.expiresAt, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAccessTokenInfo_lift(_ buf: RustBuffer) throws -> AccessTokenInfo {
return try FfiConverterTypeAccessTokenInfo.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAccessTokenInfo_lower(_ value: AccessTokenInfo) -> RustBuffer {
return FfiConverterTypeAccessTokenInfo.lower(value)
}
/**
* A client connected to the user's account.
*
* This struct provides metadata about a client connected to the user's account.
* Unlike the [`Device`] struct, "clients" encompasses both client-side and server-side
* applications - basically anything where the user is able to sign in with their
* Firefox Account.
*
*
* This data would typically be used for targeted messaging purposes, catering the
* contents of the message to what other applications the user has on their account.
*/
public struct AttachedClient: Equatable, Hashable {
public var clientId: String?
public var deviceId: String?
public var deviceType: DeviceType
public var isCurrentSession: Bool
public var name: String?
public var createdTime: Int64?
public var lastAccessTime: Int64?
public var scope: [String]?
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(clientId: String?, deviceId: String?, deviceType: DeviceType, isCurrentSession: Bool, name: String?, createdTime: Int64?, lastAccessTime: Int64?, scope: [String]?) {
self.clientId = clientId
self.deviceId = deviceId
self.deviceType = deviceType
self.isCurrentSession = isCurrentSession
self.name = name
self.createdTime = createdTime
self.lastAccessTime = lastAccessTime
self.scope = scope
}
}
#if compiler(>=6)
extension AttachedClient: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeAttachedClient: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AttachedClient {
return
try AttachedClient(
clientId: FfiConverterOptionString.read(from: &buf),
deviceId: FfiConverterOptionString.read(from: &buf),
deviceType: FfiConverterTypeDeviceType.read(from: &buf),
isCurrentSession: FfiConverterBool.read(from: &buf),
name: FfiConverterOptionString.read(from: &buf),
createdTime: FfiConverterOptionInt64.read(from: &buf),
lastAccessTime: FfiConverterOptionInt64.read(from: &buf),
scope: FfiConverterOptionSequenceString.read(from: &buf)
)
}
public static func write(_ value: AttachedClient, into buf: inout [UInt8]) {
FfiConverterOptionString.write(value.clientId, into: &buf)
FfiConverterOptionString.write(value.deviceId, into: &buf)
FfiConverterTypeDeviceType.write(value.deviceType, into: &buf)
FfiConverterBool.write(value.isCurrentSession, into: &buf)
FfiConverterOptionString.write(value.name, into: &buf)
FfiConverterOptionInt64.write(value.createdTime, into: &buf)
FfiConverterOptionInt64.write(value.lastAccessTime, into: &buf)
FfiConverterOptionSequenceString.write(value.scope, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAttachedClient_lift(_ buf: RustBuffer) throws -> AttachedClient {
return try FfiConverterTypeAttachedClient.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAttachedClient_lower(_ value: AttachedClient) -> RustBuffer {
return FfiConverterTypeAttachedClient.lower(value)
}
/**
* Information about the authorization state of the application.
*
* This struct represents metadata about whether the application is currently
* connected to the user's account.
*/
public struct AuthorizationInfo: Equatable, Hashable {
public var active: Bool
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(active: Bool) {
self.active = active
}
}
#if compiler(>=6)
extension AuthorizationInfo: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeAuthorizationInfo: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AuthorizationInfo {
return
try AuthorizationInfo(
active: FfiConverterBool.read(from: &buf)
)
}
public static func write(_ value: AuthorizationInfo, into buf: inout [UInt8]) {
FfiConverterBool.write(value.active, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAuthorizationInfo_lift(_ buf: RustBuffer) throws -> AuthorizationInfo {
return try FfiConverterTypeAuthorizationInfo.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAuthorizationInfo_lower(_ value: AuthorizationInfo) -> RustBuffer {
return FfiConverterTypeAuthorizationInfo.lower(value)
}
/**
* Parameters provided in an incoming OAuth request.
*
* This struct represents parameters obtained from an incoming OAuth request - that is,
* the values that an OAuth client would append to the authorization URL when initiating
* an OAuth sign-in flow.
*/
public struct AuthorizationParameters: Equatable, Hashable {
public var clientId: String
public var scope: [String]
public var state: String
public var accessType: String
public var codeChallenge: String?
public var codeChallengeMethod: String?
public var keysJwk: String?
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(clientId: String, scope: [String], state: String, accessType: String, codeChallenge: String?, codeChallengeMethod: String?, keysJwk: String?) {
self.clientId = clientId
self.scope = scope
self.state = state
self.accessType = accessType
self.codeChallenge = codeChallenge
self.codeChallengeMethod = codeChallengeMethod
self.keysJwk = keysJwk
}
}
#if compiler(>=6)
extension AuthorizationParameters: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeAuthorizationParameters: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AuthorizationParameters {
return
try AuthorizationParameters(
clientId: FfiConverterString.read(from: &buf),
scope: FfiConverterSequenceString.read(from: &buf),
state: FfiConverterString.read(from: &buf),
accessType: FfiConverterString.read(from: &buf),
codeChallenge: FfiConverterOptionString.read(from: &buf),
codeChallengeMethod: FfiConverterOptionString.read(from: &buf),
keysJwk: FfiConverterOptionString.read(from: &buf)
)
}
public static func write(_ value: AuthorizationParameters, into buf: inout [UInt8]) {
FfiConverterString.write(value.clientId, into: &buf)
FfiConverterSequenceString.write(value.scope, into: &buf)
FfiConverterString.write(value.state, into: &buf)
FfiConverterString.write(value.accessType, into: &buf)
FfiConverterOptionString.write(value.codeChallenge, into: &buf)
FfiConverterOptionString.write(value.codeChallengeMethod, into: &buf)
FfiConverterOptionString.write(value.keysJwk, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAuthorizationParameters_lift(_ buf: RustBuffer) throws -> AuthorizationParameters {
return try FfiConverterTypeAuthorizationParameters.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAuthorizationParameters_lower(_ value: AuthorizationParameters) -> RustBuffer {
return FfiConverterTypeAuthorizationParameters.lower(value)
}
/**
* The payload sent when invoking a "close tabs" command.
*/
public struct CloseTabsPayload: Equatable, Hashable {
/**
* The URLs of the tabs to close.
*/
public var urls: [String]
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(
/**
* The URLs of the tabs to close.
*/urls: [String]) {
self.urls = urls
}
}
#if compiler(>=6)
extension CloseTabsPayload: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeCloseTabsPayload: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CloseTabsPayload {
return
try CloseTabsPayload(
urls: FfiConverterSequenceString.read(from: &buf)
)
}
public static func write(_ value: CloseTabsPayload, into buf: inout [UInt8]) {
FfiConverterSequenceString.write(value.urls, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeCloseTabsPayload_lift(_ buf: RustBuffer) throws -> CloseTabsPayload {
return try FfiConverterTypeCloseTabsPayload.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeCloseTabsPayload_lower(_ value: CloseTabsPayload) -> RustBuffer {
return FfiConverterTypeCloseTabsPayload.lower(value)
}
/**
* A device connected to the user's account.
*
* This struct provides metadata about a device connected to the user's account.
* This data would typically be used to display e.g. the list of candidate devices
* in a "send tab" menu.
*/
public struct Device: Equatable, Hashable {
public var id: String
public var displayName: String
public var deviceType: DeviceType
public var capabilities: [DeviceCapability]
public var pushSubscription: DevicePushSubscription?
public var pushEndpointExpired: Bool
public var isCurrentDevice: Bool
public var lastAccessTime: Int64?
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(id: String, displayName: String, deviceType: DeviceType, capabilities: [DeviceCapability], pushSubscription: DevicePushSubscription?, pushEndpointExpired: Bool, isCurrentDevice: Bool, lastAccessTime: Int64?) {
self.id = id
self.displayName = displayName
self.deviceType = deviceType
self.capabilities = capabilities
self.pushSubscription = pushSubscription
self.pushEndpointExpired = pushEndpointExpired
self.isCurrentDevice = isCurrentDevice
self.lastAccessTime = lastAccessTime
}
}
#if compiler(>=6)
extension Device: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeDevice: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Device {
return
try Device(
id: FfiConverterString.read(from: &buf),
displayName: FfiConverterString.read(from: &buf),
deviceType: FfiConverterTypeDeviceType.read(from: &buf),
capabilities: FfiConverterSequenceTypeDeviceCapability.read(from: &buf),
pushSubscription: FfiConverterOptionTypeDevicePushSubscription.read(from: &buf),
pushEndpointExpired: FfiConverterBool.read(from: &buf),
isCurrentDevice: FfiConverterBool.read(from: &buf),
lastAccessTime: FfiConverterOptionInt64.read(from: &buf)
)
}
public static func write(_ value: Device, into buf: inout [UInt8]) {
FfiConverterString.write(value.id, into: &buf)
FfiConverterString.write(value.displayName, into: &buf)
FfiConverterTypeDeviceType.write(value.deviceType, into: &buf)
FfiConverterSequenceTypeDeviceCapability.write(value.capabilities, into: &buf)
FfiConverterOptionTypeDevicePushSubscription.write(value.pushSubscription, into: &buf)
FfiConverterBool.write(value.pushEndpointExpired, into: &buf)
FfiConverterBool.write(value.isCurrentDevice, into: &buf)
FfiConverterOptionInt64.write(value.lastAccessTime, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeDevice_lift(_ buf: RustBuffer) throws -> Device {
return try FfiConverterTypeDevice.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeDevice_lower(_ value: Device) -> RustBuffer {
return FfiConverterTypeDevice.lower(value)
}
/**
* Device configuration
*/
public struct DeviceConfig: Equatable, Hashable {
public var name: String
public var deviceType: DeviceType
public var capabilities: [DeviceCapability]
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(name: String, deviceType: DeviceType, capabilities: [DeviceCapability]) {
self.name = name
self.deviceType = deviceType
self.capabilities = capabilities
}
}
#if compiler(>=6)
extension DeviceConfig: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeDeviceConfig: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DeviceConfig {
return
try DeviceConfig(
name: FfiConverterString.read(from: &buf),
deviceType: FfiConverterTypeDeviceType.read(from: &buf),
capabilities: FfiConverterSequenceTypeDeviceCapability.read(from: &buf)
)
}
public static func write(_ value: DeviceConfig, into buf: inout [UInt8]) {
FfiConverterString.write(value.name, into: &buf)
FfiConverterTypeDeviceType.write(value.deviceType, into: &buf)
FfiConverterSequenceTypeDeviceCapability.write(value.capabilities, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeDeviceConfig_lift(_ buf: RustBuffer) throws -> DeviceConfig {
return try FfiConverterTypeDeviceConfig.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeDeviceConfig_lower(_ value: DeviceConfig) -> RustBuffer {
return FfiConverterTypeDeviceConfig.lower(value)
}
/**
* Details of a web-push subscription endpoint.
*
* This struct encapsulates the details of a web-push subscription endpoint,
* including all the information necessary to send a notification to its owner.
* Devices attached to the user's account may register one of these in order
* to receive timely updates about account-related events.
*
* Managing a web-push subscription is outside of the scope of this component.
*/
public struct DevicePushSubscription: Equatable, Hashable {
public var endpoint: String
public var publicKey: String
public var authKey: String
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(endpoint: String, publicKey: String, authKey: String) {
self.endpoint = endpoint
self.publicKey = publicKey
self.authKey = authKey
}
}
#if compiler(>=6)
extension DevicePushSubscription: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeDevicePushSubscription: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DevicePushSubscription {
return
try DevicePushSubscription(
endpoint: FfiConverterString.read(from: &buf),
publicKey: FfiConverterString.read(from: &buf),
authKey: FfiConverterString.read(from: &buf)
)
}
public static func write(_ value: DevicePushSubscription, into buf: inout [UInt8]) {
FfiConverterString.write(value.endpoint, into: &buf)
FfiConverterString.write(value.publicKey, into: &buf)
FfiConverterString.write(value.authKey, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeDevicePushSubscription_lift(_ buf: RustBuffer) throws -> DevicePushSubscription {
return try FfiConverterTypeDevicePushSubscription.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeDevicePushSubscription_lower(_ value: DevicePushSubscription) -> RustBuffer {
return FfiConverterTypeDevicePushSubscription.lower(value)
}
public struct FxaConfig: Equatable, Hashable {
/**
* FxaServer to connect with
*/
public var server: FxaServer
/**
* Registered OAuth client id of the application.
*/
public var clientId: String
/**
* `redirect_uri` - the registered OAuth redirect URI of the application.
*/
public var redirectUri: String
/**
* URL for the user's Sync Tokenserver. This can be used to support users who self-host their
* sync data. If `None` then it will default to the Mozilla-hosted Sync server.
*
* Note: this lives here for historical reasons, but probably shouldn't. Applications pass
* the token server URL they get from `fxa-client` to `SyncManager`. It would be simpler to
* cut out `fxa-client` out of the middle and have applications send the overridden URL
* directly to `SyncManager`.
*/
public var tokenServerUrlOverride: String?
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(
/**
* FxaServer to connect with
*/server: FxaServer,
/**
* Registered OAuth client id of the application.
*/clientId: String,
/**
* `redirect_uri` - the registered OAuth redirect URI of the application.
*/redirectUri: String,
/**
* URL for the user's Sync Tokenserver. This can be used to support users who self-host their
* sync data. If `None` then it will default to the Mozilla-hosted Sync server.
*
* Note: this lives here for historical reasons, but probably shouldn't. Applications pass
* the token server URL they get from `fxa-client` to `SyncManager`. It would be simpler to
* cut out `fxa-client` out of the middle and have applications send the overridden URL
* directly to `SyncManager`.
*/tokenServerUrlOverride: String? = nil) {
self.server = server
self.clientId = clientId
self.redirectUri = redirectUri
self.tokenServerUrlOverride = tokenServerUrlOverride
}
}
#if compiler(>=6)
extension FxaConfig: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFxaConfig: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FxaConfig {
return
try FxaConfig(
server: FfiConverterTypeFxaServer.read(from: &buf),
clientId: FfiConverterString.read(from: &buf),
redirectUri: FfiConverterString.read(from: &buf),
tokenServerUrlOverride: FfiConverterOptionString.read(from: &buf)
)
}
public static func write(_ value: FxaConfig, into buf: inout [UInt8]) {
FfiConverterTypeFxaServer.write(value.server, into: &buf)
FfiConverterString.write(value.clientId, into: &buf)
FfiConverterString.write(value.redirectUri, into: &buf)
FfiConverterOptionString.write(value.tokenServerUrlOverride, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaConfig_lift(_ buf: RustBuffer) throws -> FxaConfig {
return try FfiConverterTypeFxaConfig.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaConfig_lower(_ value: FxaConfig) -> RustBuffer {
return FfiConverterTypeFxaConfig.lower(value)
}
/**
* Local device that's connecting to FxA
*
* This is returned by the device update methods and represents the server's view of the local
* device.
*/
public struct LocalDevice: Equatable, Hashable {
public var id: String
public var displayName: String
public var deviceType: DeviceType
public var capabilities: [DeviceCapability]
public var pushSubscription: DevicePushSubscription?
public var pushEndpointExpired: Bool
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(id: String, displayName: String, deviceType: DeviceType, capabilities: [DeviceCapability], pushSubscription: DevicePushSubscription?, pushEndpointExpired: Bool) {
self.id = id
self.displayName = displayName
self.deviceType = deviceType
self.capabilities = capabilities
self.pushSubscription = pushSubscription
self.pushEndpointExpired = pushEndpointExpired
}
}
#if compiler(>=6)
extension LocalDevice: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeLocalDevice: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> LocalDevice {
return
try LocalDevice(
id: FfiConverterString.read(from: &buf),
displayName: FfiConverterString.read(from: &buf),
deviceType: FfiConverterTypeDeviceType.read(from: &buf),
capabilities: FfiConverterSequenceTypeDeviceCapability.read(from: &buf),
pushSubscription: FfiConverterOptionTypeDevicePushSubscription.read(from: &buf),
pushEndpointExpired: FfiConverterBool.read(from: &buf)
)
}
public static func write(_ value: LocalDevice, into buf: inout [UInt8]) {
FfiConverterString.write(value.id, into: &buf)
FfiConverterString.write(value.displayName, into: &buf)
FfiConverterTypeDeviceType.write(value.deviceType, into: &buf)
FfiConverterSequenceTypeDeviceCapability.write(value.capabilities, into: &buf)
FfiConverterOptionTypeDevicePushSubscription.write(value.pushSubscription, into: &buf)
FfiConverterBool.write(value.pushEndpointExpired, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeLocalDevice_lift(_ buf: RustBuffer) throws -> LocalDevice {
return try FfiConverterTypeLocalDevice.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeLocalDevice_lower(_ value: LocalDevice) -> RustBuffer {
return FfiConverterTypeLocalDevice.lower(value)
}
/**
* Information about the user that controls a Firefox Account.
*
* This struct represents details about the user themselves, and would typically be
* used to customize account-related UI in the browser so that it is personalize
* for the current user.
*/
public struct Profile: Equatable, Hashable {
/**
* The user's account uid
*
* This is an opaque immutable unique identifier for their account.
*/
public var uid: String
/**
* The user's current primary email address.
*
* Note that unlike the `uid` field, the email address may change over time.
*/
public var email: String
/**
* The user's preferred textual display name.
*/
public var displayName: String?
/**
* The URL of a profile picture representing the user.
*
* All accounts have a corresponding profile picture. If the user has not
* provided one then a default image is used.
*/
public var avatar: String
/**
* Whether the `avatar` URL represents the default avatar image.
*/
public var isDefaultAvatar: Bool
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(
/**
* The user's account uid
*
* This is an opaque immutable unique identifier for their account.
*/uid: String,
/**
* The user's current primary email address.
*
* Note that unlike the `uid` field, the email address may change over time.
*/email: String,
/**
* The user's preferred textual display name.
*/displayName: String?,
/**
* The URL of a profile picture representing the user.
*
* All accounts have a corresponding profile picture. If the user has not
* provided one then a default image is used.
*/avatar: String,
/**
* Whether the `avatar` URL represents the default avatar image.
*/isDefaultAvatar: Bool) {
self.uid = uid
self.email = email
self.displayName = displayName
self.avatar = avatar
self.isDefaultAvatar = isDefaultAvatar
}
}
#if compiler(>=6)
extension Profile: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeProfile: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Profile {
return
try Profile(
uid: FfiConverterString.read(from: &buf),
email: FfiConverterString.read(from: &buf),
displayName: FfiConverterOptionString.read(from: &buf),
avatar: FfiConverterString.read(from: &buf),
isDefaultAvatar: FfiConverterBool.read(from: &buf)
)
}
public static func write(_ value: Profile, into buf: inout [UInt8]) {
FfiConverterString.write(value.uid, into: &buf)
FfiConverterString.write(value.email, into: &buf)
FfiConverterOptionString.write(value.displayName, into: &buf)
FfiConverterString.write(value.avatar, into: &buf)
FfiConverterBool.write(value.isDefaultAvatar, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeProfile_lift(_ buf: RustBuffer) throws -> Profile {
return try FfiConverterTypeProfile.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeProfile_lower(_ value: Profile) -> RustBuffer {
return FfiConverterTypeProfile.lower(value)
}
/**
* A cryptographic key associated with an OAuth scope.
*
* Some OAuth scopes have a corresponding client-side encryption key that is required
* in order to access protected data. This struct represents such key material in a
* format compatible with the common "JWK" standard.
*/
public struct ScopedKey: Equatable, Hashable {
/**
* The type of key.
*
* In practice for FxA, this will always be string string "oct" (short for "octal")
* to represent a raw symmetric key.
*/
public var kty: String
/**
* The OAuth scope with which this key is associated.
*/
public var scope: String
/**
* The key material, as base64-url-encoded bytes.
*
* **⚠️ Warning:** the value of this field should never be revealed outside of the
* application. For example, it should never to sent to a server or logged in a log file.
*/
public var k: String
/**
* An opaque unique identifier for this key.
*
* Unlike the `k` field, this value is not secret and may be revealed to the server.
*/
public var kid: String
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(
/**
* The type of key.
*
* In practice for FxA, this will always be string string "oct" (short for "octal")
* to represent a raw symmetric key.
*/kty: String,
/**
* The OAuth scope with which this key is associated.
*/scope: String,
/**
* The key material, as base64-url-encoded bytes.
*
* **⚠️ Warning:** the value of this field should never be revealed outside of the
* application. For example, it should never to sent to a server or logged in a log file.
*/k: String,
/**
* An opaque unique identifier for this key.
*
* Unlike the `k` field, this value is not secret and may be revealed to the server.
*/kid: String) {
self.kty = kty
self.scope = scope
self.k = k
self.kid = kid
}
}
#if compiler(>=6)
extension ScopedKey: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeScopedKey: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ScopedKey {
return
try ScopedKey(
kty: FfiConverterString.read(from: &buf),
scope: FfiConverterString.read(from: &buf),
k: FfiConverterString.read(from: &buf),
kid: FfiConverterString.read(from: &buf)
)
}
public static func write(_ value: ScopedKey, into buf: inout [UInt8]) {
FfiConverterString.write(value.kty, into: &buf)
FfiConverterString.write(value.scope, into: &buf)
FfiConverterString.write(value.k, into: &buf)
FfiConverterString.write(value.kid, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeScopedKey_lift(_ buf: RustBuffer) throws -> ScopedKey {
return try FfiConverterTypeScopedKey.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeScopedKey_lower(_ value: ScopedKey) -> RustBuffer {
return FfiConverterTypeScopedKey.lower(value)
}
/**
* The payload sent when invoking a "send tab" command.
*/
public struct SendTabPayload: Equatable, Hashable {
/**
* The navigation history of the sent tab.
*
* The last item in this list represents the page to be displayed,
* while earlier items may be included in the navigation history
* as a convenience to the user.
*/
public var entries: [TabHistoryEntry]
/**
* A unique identifier to be included in send-tab metrics.
*
* The application should treat this as opaque.
*/
public var flowId: String
/**
* A unique identifier to be included in send-tab metrics.
*
* The application should treat this as opaque.
*/
public var streamId: String
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(
/**
* The navigation history of the sent tab.
*
* The last item in this list represents the page to be displayed,
* while earlier items may be included in the navigation history
* as a convenience to the user.
*/entries: [TabHistoryEntry],
/**
* A unique identifier to be included in send-tab metrics.
*
* The application should treat this as opaque.
*/flowId: String = "",
/**
* A unique identifier to be included in send-tab metrics.
*
* The application should treat this as opaque.
*/streamId: String = "") {
self.entries = entries
self.flowId = flowId
self.streamId = streamId
}
}
#if compiler(>=6)
extension SendTabPayload: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeSendTabPayload: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SendTabPayload {
return
try SendTabPayload(
entries: FfiConverterSequenceTypeTabHistoryEntry.read(from: &buf),
flowId: FfiConverterString.read(from: &buf),
streamId: FfiConverterString.read(from: &buf)
)
}
public static func write(_ value: SendTabPayload, into buf: inout [UInt8]) {
FfiConverterSequenceTypeTabHistoryEntry.write(value.entries, into: &buf)
FfiConverterString.write(value.flowId, into: &buf)
FfiConverterString.write(value.streamId, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeSendTabPayload_lift(_ buf: RustBuffer) throws -> SendTabPayload {
return try FfiConverterTypeSendTabPayload.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeSendTabPayload_lower(_ value: SendTabPayload) -> RustBuffer {
return FfiConverterTypeSendTabPayload.lower(value)
}
/**
* An individual entry in the navigation history of a sent tab.
*/
public struct TabHistoryEntry: Equatable, Hashable {
public var title: String
public var url: String
public var isPrivate: Bool
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(title: String, url: String, isPrivate: Bool = false) {
self.title = title
self.url = url
self.isPrivate = isPrivate
}
}
#if compiler(>=6)
extension TabHistoryEntry: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeTabHistoryEntry: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TabHistoryEntry {
return
try TabHistoryEntry(
title: FfiConverterString.read(from: &buf),
url: FfiConverterString.read(from: &buf),
isPrivate: FfiConverterBool.read(from: &buf)
)
}
public static func write(_ value: TabHistoryEntry, into buf: inout [UInt8]) {
FfiConverterString.write(value.title, into: &buf)
FfiConverterString.write(value.url, into: &buf)
FfiConverterBool.write(value.isPrivate, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeTabHistoryEntry_lift(_ buf: RustBuffer) throws -> TabHistoryEntry {
return try FfiConverterTypeTabHistoryEntry.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeTabHistoryEntry_lower(_ value: TabHistoryEntry) -> RustBuffer {
return FfiConverterTypeTabHistoryEntry.lower(value)
}
/**
* An event that happened on the user's account.
*
* If the application has registered a [`DevicePushSubscription`] as part of its
* device record, then the Firefox Accounts server can send push notifications
* about important events that happen on the user's account. This enum represents
* the different kinds of event that can occur.
*/
public enum AccountEvent: Equatable, Hashable {
/**
* Sent when another device has invoked a command for this device to execute.
*
* When receiving this event, the application should inspect the contained
* command and react appropriately.
*/
case commandReceived(command: IncomingDeviceCommand
)
/**
* Sent when the user has modified their account profile information.
*
* When receiving this event, the application should request fresh profile
* information by calling [`get_profile`](FirefoxAccount::get_profile) with
* `ignore_cache` set to true, and update any profile information displayed
* in its UI.
*/
case profileUpdated
/**
* Sent when when there has been a change in authorization status.
*
* When receiving this event, the application should check whether it is
* still connected to the user's account by calling [`check_authorization_status`](
* FirefoxAccount::check_authorization_status), and updating its UI as appropriate.
*/
case accountAuthStateChanged
/**
* Sent when the user deletes their Firefox Account.
*
* When receiving this event, the application should act as though the user had
* signed out, discarding any persisted account state.
*/
case accountDestroyed
/**
* Sent when a new device connects to the user's account.
*
* When receiving this event, the application may use it to trigger an update
* of any UI that shows the list of connected devices. It may also show the
* user an informational notice about the new device, as a security measure.
*/
case deviceConnected(deviceName: String
)
/**
* Sent when a device disconnects from the user's account.
*
* When receiving this event, the application may use it to trigger an update
* of any UI that shows the list of connected devices.
*/
case deviceDisconnected(deviceId: String, isLocalDevice: Bool
)
/**
* An unknown event, most likely an event the client doesn't support yet.
*
* When receiving this event, the application should gracefully ignore it.
*/
case unknown
}
#if compiler(>=6)
extension AccountEvent: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeAccountEvent: FfiConverterRustBuffer {
typealias SwiftType = AccountEvent
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AccountEvent {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .commandReceived(command: try FfiConverterTypeIncomingDeviceCommand.read(from: &buf)
)
case 2: return .profileUpdated
case 3: return .accountAuthStateChanged
case 4: return .accountDestroyed
case 5: return .deviceConnected(deviceName: try FfiConverterString.read(from: &buf)
)
case 6: return .deviceDisconnected(deviceId: try FfiConverterString.read(from: &buf), isLocalDevice: try FfiConverterBool.read(from: &buf)
)
case 7: return .unknown
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: AccountEvent, into buf: inout [UInt8]) {
switch value {
case let .commandReceived(command):
writeInt(&buf, Int32(1))
FfiConverterTypeIncomingDeviceCommand.write(command, into: &buf)
case .profileUpdated:
writeInt(&buf, Int32(2))
case .accountAuthStateChanged:
writeInt(&buf, Int32(3))
case .accountDestroyed:
writeInt(&buf, Int32(4))
case let .deviceConnected(deviceName):
writeInt(&buf, Int32(5))
FfiConverterString.write(deviceName, into: &buf)
case let .deviceDisconnected(deviceId,isLocalDevice):
writeInt(&buf, Int32(6))
FfiConverterString.write(deviceId, into: &buf)
FfiConverterBool.write(isLocalDevice, into: &buf)
case .unknown:
writeInt(&buf, Int32(7))
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAccountEvent_lift(_ buf: RustBuffer) throws -> AccountEvent {
return try FfiConverterTypeAccountEvent.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeAccountEvent_lower(_ value: AccountEvent) -> RustBuffer {
return FfiConverterTypeAccountEvent.lower(value)
}
/**
* The result of invoking a "close tabs" command.
*
* If [`FirefoxAccount::close_tabs`] is called with more URLs than can fit
* into a single command payload, the URLs will be chunked and sent in
* multiple commands.
*
* Chunking breaks the atomicity of a "close tabs" command, but
* reduces the number of these commands that FxA sends to other devices.
* This is critical for platforms like iOS, where every command triggers a
* push message that must show a user-visible notification.
*/
public enum CloseTabsResult: Equatable, Hashable {
/**
* All URLs passed to [`FirefoxAccount::close_tabs`] were chunked and sent
* in one or more device commands.
*/
case ok
/**
* One or more URLs passed to [`FirefoxAccount::close_tabs`] couldn't be sent
* in a device command. The caller can assume that:
*
* 1. Any URL in the returned list of `urls` was not sent, and
* should be retried.
* 2. All other URLs that were passed to [`FirefoxAccount::close_tabs`], and
* that are _not_ in the list of `urls`, were chunked and sent.
*/
case tabsNotClosed(urls: [String]
)
}
#if compiler(>=6)
extension CloseTabsResult: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeCloseTabsResult: FfiConverterRustBuffer {
typealias SwiftType = CloseTabsResult
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CloseTabsResult {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .ok
case 2: return .tabsNotClosed(urls: try FfiConverterSequenceString.read(from: &buf)
)
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: CloseTabsResult, into buf: inout [UInt8]) {
switch value {
case .ok:
writeInt(&buf, Int32(1))
case let .tabsNotClosed(urls):
writeInt(&buf, Int32(2))
FfiConverterSequenceString.write(urls, into: &buf)
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeCloseTabsResult_lift(_ buf: RustBuffer) throws -> CloseTabsResult {
return try FfiConverterTypeCloseTabsResult.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeCloseTabsResult_lower(_ value: CloseTabsResult) -> RustBuffer {
return FfiConverterTypeCloseTabsResult.lower(value)
}
/**
* A "capability" offered by a device.
*
* In the FxA ecosystem, connected devices may advertise their ability to respond
* to various "commands" that can be invoked by other devices. The details of
* executing these commands are encapsulated as part of the FxA Client component,
* so consumers simply need to select which ones they want to support, and can
* use the variants of this enum to do so.
*/
public enum DeviceCapability: Equatable, Hashable {
case sendTab
case closeTabs
}
#if compiler(>=6)
extension DeviceCapability: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeDeviceCapability: FfiConverterRustBuffer {
typealias SwiftType = DeviceCapability
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DeviceCapability {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .sendTab
case 2: return .closeTabs
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: DeviceCapability, into buf: inout [UInt8]) {
switch value {
case .sendTab:
writeInt(&buf, Int32(1))
case .closeTabs:
writeInt(&buf, Int32(2))
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeDeviceCapability_lift(_ buf: RustBuffer) throws -> DeviceCapability {
return try FfiConverterTypeDeviceCapability.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeDeviceCapability_lower(_ value: DeviceCapability) -> RustBuffer {
return FfiConverterTypeDeviceCapability.lower(value)
}
/**
* Public error type thrown by many [`FirefoxAccount`] operations.
*
* Precise details of the error are hidden from consumers. The type of the error indicates how the
* calling code should respond.
*/
public
enum FxaError: Swift.Error, Equatable, Hashable, Foundation.LocalizedError {
/**
* Thrown when there was a problem with the authentication status of the account,
* such as an expired token. The application should [check its authorization status](
* FirefoxAccount::check_authorization_status) to see whether it has been disconnected,
* or retry the operation with a freshly-generated token.
*/
case Authentication(message: String)
/**
* Thrown when an authenticated account isn't allowed to perform some operation. Unlike
* `Authentication`, there's no problem with the account status. In some cases it
* might be possible to request additional scopes, and once granted, the operation
* may succeed.
*/
case Forbidden(message: String)
/**
* Thrown if an operation fails due to network access problems.
* The application may retry at a later time once connectivity is restored.
*/
case Network(message: String)
/**
* Thrown if the application attempts to complete an OAuth flow when no OAuth flow
* has been initiated. This may indicate a user who navigated directly to the OAuth
* `redirect_uri` for the application.
*
* **Note:** This error is currently only thrown in the Swift language bindings.
*/
case NoExistingAuthFlow(message: String)
/**
* Thrown if the application attempts to complete an OAuth flow, but the state
* tokens returned from the Firefox Account server do not match with the ones
* expected by the client.
* This may indicate a stale OAuth flow, or potentially an attempted hijacking
* of the flow by an attacker. The signin attempt cannot be completed.
*
* **Note:** This error is currently only thrown in the Swift language bindings.
*/
case WrongAuthFlow(message: String)
/**
* Origin mismatch when handling a pairing flow
*
* The most likely cause of this is that a user tried to pair together two firefox instances
* that are configured to use different servers.
*/
case OriginMismatch(message: String)
/**
* A scoped key was missing in the server response when requesting the OLD_SYNC scope.
*/
case SyncScopedKeyMissingInServerResponse(message: String)
/**
* Thrown if there is a panic in the underlying Rust code.
*
* **Note:** This error is currently only thrown in the Kotlin language bindings.
*/
case Panic(message: String)
/**
* A catch-all for other unspecified errors.
*/
case Other(message: String)
public var errorDescription: String? {
String(reflecting: self)
}
}
#if compiler(>=6)
extension FxaError: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFxaError: FfiConverterRustBuffer {
typealias SwiftType = FxaError
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FxaError {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .Authentication(
message: try FfiConverterString.read(from: &buf)
)
case 2: return .Forbidden(
message: try FfiConverterString.read(from: &buf)
)
case 3: return .Network(
message: try FfiConverterString.read(from: &buf)
)
case 4: return .NoExistingAuthFlow(
message: try FfiConverterString.read(from: &buf)
)
case 5: return .WrongAuthFlow(
message: try FfiConverterString.read(from: &buf)
)
case 6: return .OriginMismatch(
message: try FfiConverterString.read(from: &buf)
)
case 7: return .SyncScopedKeyMissingInServerResponse(
message: try FfiConverterString.read(from: &buf)
)
case 8: return .Panic(
message: try FfiConverterString.read(from: &buf)
)
case 9: return .Other(
message: try FfiConverterString.read(from: &buf)
)
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: FxaError, into buf: inout [UInt8]) {
switch value {
case .Authentication(_ /* message is ignored*/):
writeInt(&buf, Int32(1))
case .Forbidden(_ /* message is ignored*/):
writeInt(&buf, Int32(2))
case .Network(_ /* message is ignored*/):
writeInt(&buf, Int32(3))
case .NoExistingAuthFlow(_ /* message is ignored*/):
writeInt(&buf, Int32(4))
case .WrongAuthFlow(_ /* message is ignored*/):
writeInt(&buf, Int32(5))
case .OriginMismatch(_ /* message is ignored*/):
writeInt(&buf, Int32(6))
case .SyncScopedKeyMissingInServerResponse(_ /* message is ignored*/):
writeInt(&buf, Int32(7))
case .Panic(_ /* message is ignored*/):
writeInt(&buf, Int32(8))
case .Other(_ /* message is ignored*/):
writeInt(&buf, Int32(9))
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaError_lift(_ buf: RustBuffer) throws -> FxaError {
return try FfiConverterTypeFxaError.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaError_lower(_ value: FxaError) -> RustBuffer {
return FfiConverterTypeFxaError.lower(value)
}
/**
* Fxa event
*
* These are the events that consumers send to [crate::FxaStateMachine::process_event]
*/
public enum FxaEvent: Equatable, Hashable {
/**
* Initialize the state machine. This must be the first event sent.
*/
case initialize(deviceConfig: DeviceConfig
)
/**
* Begin an oauth flow
*
* If successful, the state machine will transition the [FxaState::Authenticating]. The next
* step is to navigate the user to the `oauth_url` and let them sign and authorize the client.
*
* This event is valid for the `Disconnected`, `AuthIssues`, and `Authenticating` states. If
* the state machine is in the `Authenticating` state, then this will forget the current OAuth
* flow and start a new one.
*/
case beginOAuthFlow(service: String, scopes: [String], entrypoint: String
)
/**
* Begin an oauth flow using a URL from a pairing code
*
* If successful, the state machine will transition the [FxaState::Authenticating]. The next
* step is to navigate the user to the `oauth_url` and let them sign and authorize the client.
*
* This event is valid for the `Disconnected`, `AuthIssues`, and `Authenticating` states. If
* the state machine is in the `Authenticating` state, then this will forget the current OAuth
* flow and start a new one.
*/
case beginPairingFlow(pairingUrl: String, service: String, scopes: [String], entrypoint: String
)
/**
* Complete an OAuth flow.
*
* Send this event after the user has navigated through the OAuth flow and has reached the
* redirect URI. Extract `code` and `state` from the query parameters or web channel. If
* successful the state machine will transition to [FxaState::Connected].
*
* This event is valid for the `Authenticating` state.
*/
case completeOAuthFlow(code: String, state: String
)
/**
* Cancel an OAuth flow.
*
* Use this to cancel an in-progress OAuth, returning to [FxaState::Disconnected] so the
* process can begin again.
*
* This event is valid for the `Authenticating` state.
*/
case cancelOAuthFlow
/**
* Check the authorization status for a connected account.
*
* Send this when issues are detected with the auth tokens for a connected account. It will
* double check for authentication issues with the account. If it detects them, the state
* machine will transition to [FxaState::AuthIssues]. From there you can start an OAuth flow
* again to re-connect the user.
*
* This event is valid for the `Connected` state.
*/
case checkAuthorizationStatus
/**
* An `fxaccounts:change_password` WebChannel message arrived on the device that just changed
* its password. `json_payload` is the `data` object of that message and contains the new
* session token. The state machine swaps the session token for a new refresh token and
* re-initialises the device record.
*
* This event is valid for the `Connected` and `AuthIssues` states. In `Authenticating` it
* is a no-op so the in-progress OAuth flow is not disrupted.
*/
case webChannelPasswordChange(jsonPayload: String
)
/**
* Disconnect the user
*
* Send this when the user is asking to be logged out. The state machine will transition to
* [FxaState::Disconnected].
*
* This event is valid for the `Connected` state.
*/
case disconnect
/**
* Force a call to [FirefoxAccount::get_profile]
*
* This is used for testing the auth/network retry code, since it hits the network and
* requires and auth token.
*
* This event is valid for the `Connected` state.
*/
case callGetProfile
}
#if compiler(>=6)
extension FxaEvent: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFxaEvent: FfiConverterRustBuffer {
typealias SwiftType = FxaEvent
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FxaEvent {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .initialize(deviceConfig: try FfiConverterTypeDeviceConfig.read(from: &buf)
)
case 2: return .beginOAuthFlow(service: try FfiConverterString.read(from: &buf), scopes: try FfiConverterSequenceString.read(from: &buf), entrypoint: try FfiConverterString.read(from: &buf)
)
case 3: return .beginPairingFlow(pairingUrl: try FfiConverterString.read(from: &buf), service: try FfiConverterString.read(from: &buf), scopes: try FfiConverterSequenceString.read(from: &buf), entrypoint: try FfiConverterString.read(from: &buf)
)
case 4: return .completeOAuthFlow(code: try FfiConverterString.read(from: &buf), state: try FfiConverterString.read(from: &buf)
)
case 5: return .cancelOAuthFlow
case 6: return .checkAuthorizationStatus
case 7: return .webChannelPasswordChange(jsonPayload: try FfiConverterString.read(from: &buf)
)
case 8: return .disconnect
case 9: return .callGetProfile
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: FxaEvent, into buf: inout [UInt8]) {
switch value {
case let .initialize(deviceConfig):
writeInt(&buf, Int32(1))
FfiConverterTypeDeviceConfig.write(deviceConfig, into: &buf)
case let .beginOAuthFlow(service,scopes,entrypoint):
writeInt(&buf, Int32(2))
FfiConverterString.write(service, into: &buf)
FfiConverterSequenceString.write(scopes, into: &buf)
FfiConverterString.write(entrypoint, into: &buf)
case let .beginPairingFlow(pairingUrl,service,scopes,entrypoint):
writeInt(&buf, Int32(3))
FfiConverterString.write(pairingUrl, into: &buf)
FfiConverterString.write(service, into: &buf)
FfiConverterSequenceString.write(scopes, into: &buf)
FfiConverterString.write(entrypoint, into: &buf)
case let .completeOAuthFlow(code,state):
writeInt(&buf, Int32(4))
FfiConverterString.write(code, into: &buf)
FfiConverterString.write(state, into: &buf)
case .cancelOAuthFlow:
writeInt(&buf, Int32(5))
case .checkAuthorizationStatus:
writeInt(&buf, Int32(6))
case let .webChannelPasswordChange(jsonPayload):
writeInt(&buf, Int32(7))
FfiConverterString.write(jsonPayload, into: &buf)
case .disconnect:
writeInt(&buf, Int32(8))
case .callGetProfile:
writeInt(&buf, Int32(9))
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaEvent_lift(_ buf: RustBuffer) throws -> FxaEvent {
return try FfiConverterTypeFxaEvent.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaEvent_lower(_ value: FxaEvent) -> RustBuffer {
return FfiConverterTypeFxaEvent.lower(value)
}
public enum FxaServer: Equatable, Hashable {
case release
case stable
case stage
case china
case localDev
case custom(url: String
)
}
#if compiler(>=6)
extension FxaServer: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFxaServer: FfiConverterRustBuffer {
typealias SwiftType = FxaServer
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FxaServer {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .release
case 2: return .stable
case 3: return .stage
case 4: return .china
case 5: return .localDev
case 6: return .custom(url: try FfiConverterString.read(from: &buf)
)
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: FxaServer, into buf: inout [UInt8]) {
switch value {
case .release:
writeInt(&buf, Int32(1))
case .stable:
writeInt(&buf, Int32(2))
case .stage:
writeInt(&buf, Int32(3))
case .china:
writeInt(&buf, Int32(4))
case .localDev:
writeInt(&buf, Int32(5))
case let .custom(url):
writeInt(&buf, Int32(6))
FfiConverterString.write(url, into: &buf)
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaServer_lift(_ buf: RustBuffer) throws -> FxaServer {
return try FfiConverterTypeFxaServer.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaServer_lower(_ value: FxaServer) -> RustBuffer {
return FfiConverterTypeFxaServer.lower(value)
}
/**
* Fxa state
*
* These are the states of [crate::FxaStateMachine] that consumers observe.
*/
public indirect enum FxaState: Equatable, Hashable {
/**
* The state machine needs to be initialized via [Event::Initialize].
*/
case uninitialized
/**
* User has not connected to FxA or has logged out
*/
case disconnected
/**
* User is currently performing an OAuth flow.
*
* Initial state is what we transition to if the flow is cancelled or fails.
*/
case authenticating(oauthUrl: String, initialState: FxaState
)
/**
* User is currently connected to FxA
*/
case connected
/**
* User was connected to FxA, but we observed issues with the auth tokens.
* The user needs to reauthenticate before the account can be used.
*/
case authIssues
}
#if compiler(>=6)
extension FxaState: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFxaState: FfiConverterRustBuffer {
typealias SwiftType = FxaState
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FxaState {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .uninitialized
case 2: return .disconnected
case 3: return .authenticating(oauthUrl: try FfiConverterString.read(from: &buf), initialState: try FfiConverterTypeFxaState.read(from: &buf)
)
case 4: return .connected
case 5: return .authIssues
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: FxaState, into buf: inout [UInt8]) {
switch value {
case .uninitialized:
writeInt(&buf, Int32(1))
case .disconnected:
writeInt(&buf, Int32(2))
case let .authenticating(oauthUrl,initialState):
writeInt(&buf, Int32(3))
FfiConverterString.write(oauthUrl, into: &buf)
FfiConverterTypeFxaState.write(initialState, into: &buf)
case .connected:
writeInt(&buf, Int32(4))
case .authIssues:
writeInt(&buf, Int32(5))
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaState_lift(_ buf: RustBuffer) throws -> FxaState {
return try FfiConverterTypeFxaState.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFxaState_lower(_ value: FxaState) -> RustBuffer {
return FfiConverterTypeFxaState.lower(value)
}
/**
* A command invoked by another device.
*
* This enum represents all possible commands that can be invoked on
* the device. It is the responsibility of the application to interpret
* each command.
*/
public enum IncomingDeviceCommand: Equatable, Hashable {
/**
* Indicates that a tab has been sent to this device.
*/
case tabReceived(sender: Device?, payload: SendTabPayload
)
/**
* Indicates that the sender wants to close one or more tabs on this device.
*/
case tabsClosed(sender: Device?, payload: CloseTabsPayload
)
}
#if compiler(>=6)
extension IncomingDeviceCommand: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeIncomingDeviceCommand: FfiConverterRustBuffer {
typealias SwiftType = IncomingDeviceCommand
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> IncomingDeviceCommand {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .tabReceived(sender: try FfiConverterOptionTypeDevice.read(from: &buf), payload: try FfiConverterTypeSendTabPayload.read(from: &buf)
)
case 2: return .tabsClosed(sender: try FfiConverterOptionTypeDevice.read(from: &buf), payload: try FfiConverterTypeCloseTabsPayload.read(from: &buf)
)
default: throw UniffiInternalError.unexpectedEnumCase
}
}
public static func write(_ value: IncomingDeviceCommand, into buf: inout [UInt8]) {
switch value {
case let .tabReceived(sender,payload):
writeInt(&buf, Int32(1))
FfiConverterOptionTypeDevice.write(sender, into: &buf)
FfiConverterTypeSendTabPayload.write(payload, into: &buf)
case let .tabsClosed(sender,payload):
writeInt(&buf, Int32(2))
FfiConverterOptionTypeDevice.write(sender, into: &buf)
FfiConverterTypeCloseTabsPayload.write(payload, into: &buf)
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeIncomingDeviceCommand_lift(_ buf: RustBuffer) throws -> IncomingDeviceCommand {
return try FfiConverterTypeIncomingDeviceCommand.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeIncomingDeviceCommand_lower(_ value: IncomingDeviceCommand) -> RustBuffer {
return FfiConverterTypeIncomingDeviceCommand.lower(value)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionInt64: FfiConverterRustBuffer {
typealias SwiftType = Int64?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterInt64.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterInt64.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
typealias SwiftType = String?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterString.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterString.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeDevice: FfiConverterRustBuffer {
typealias SwiftType = Device?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeDevice.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeDevice.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeDevicePushSubscription: FfiConverterRustBuffer {
typealias SwiftType = DevicePushSubscription?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeDevicePushSubscription.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeDevicePushSubscription.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeScopedKey: FfiConverterRustBuffer {
typealias SwiftType = ScopedKey?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeScopedKey.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeScopedKey.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionSequenceString: FfiConverterRustBuffer {
typealias SwiftType = [String]?
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterSequenceString.write(value, into: &buf)
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterSequenceString.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
typealias SwiftType = [String]
public static func write(_ value: [String], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterString.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] {
let len: Int32 = try readInt(&buf)
var seq = [String]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterString.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeAttachedClient: FfiConverterRustBuffer {
typealias SwiftType = [AttachedClient]
public static func write(_ value: [AttachedClient], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeAttachedClient.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [AttachedClient] {
let len: Int32 = try readInt(&buf)
var seq = [AttachedClient]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeAttachedClient.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeDevice: FfiConverterRustBuffer {
typealias SwiftType = [Device]
public static func write(_ value: [Device], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeDevice.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Device] {
let len: Int32 = try readInt(&buf)
var seq = [Device]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeDevice.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeTabHistoryEntry: FfiConverterRustBuffer {
typealias SwiftType = [TabHistoryEntry]
public static func write(_ value: [TabHistoryEntry], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeTabHistoryEntry.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [TabHistoryEntry] {
let len: Int32 = try readInt(&buf)
var seq = [TabHistoryEntry]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeTabHistoryEntry.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeDeviceCapability: FfiConverterRustBuffer {
typealias SwiftType = [DeviceCapability]
public static func write(_ value: [DeviceCapability], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeDeviceCapability.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [DeviceCapability] {
let len: Int32 = try readInt(&buf)
var seq = [DeviceCapability]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeDeviceCapability.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeIncomingDeviceCommand: FfiConverterRustBuffer {
typealias SwiftType = [IncomingDeviceCommand]
public static func write(_ value: [IncomingDeviceCommand], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeIncomingDeviceCommand.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [IncomingDeviceCommand] {
let len: Int32 = try readInt(&buf)
var seq = [IncomingDeviceCommand]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeIncomingDeviceCommand.read(from: &buf))
}
return seq
}
}
private enum InitializationResult {
case ok
case contractVersionMismatch
case apiChecksumMismatch
}
// Use a global variable to perform the versioning checks. Swift ensures that
// the code inside is only computed once.
private let initializationResult: InitializationResult = {
// Get the bindings contract version from our ComponentInterface
let bindings_contract_version = 30
// Get the scaffolding contract version by calling the into the dylib
let scaffolding_contract_version = ffi_fxa_client_uniffi_contract_version()
if bindings_contract_version != scaffolding_contract_version {
return InitializationResult.contractVersionMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_simulate_network_error() != 27883) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_connection_success_url() != 44793) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_manage_account_url() != 43415) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_manage_devices_url() != 39925) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_token_server_endpoint_url() != 8479) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_matches_server() != 28649) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_check_authorization_status() != 62263) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_disconnect() != 44105) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_pairing_authority_url() != 31881) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_state() != 250) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_handle_web_channel_login() != 62645) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_on_auth_issues() != 16011) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_process_event() != 12576) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_reset_auth_recheck_timer() != 41596) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_simulate_permanent_auth_token_issue() != 54132) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_simulate_temporary_auth_token_issue() != 41850) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_clear_device_name() != 40392) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_ensure_capabilities() != 2432) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_attached_clients() != 51227) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_current_device_id() != 35413) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_devices() != 42244) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_initialize_device() != 62346) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_set_device_name() != 47100) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_profile() != 6602) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_close_tabs() != 6639) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_handle_push_message() != 17576) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_poll_device_commands() != 1100) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_send_single_tab() != 10991) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_set_push_subscription() != 57784) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_to_json() != 13376) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_gather_telemetry() != 63243) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_authorize_code_using_session_token() != 58951) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_clear_access_token_cache() != 37464) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_access_token() != 61641) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_session_token() != 22142) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_get_signed_in_user_for_web_channel() != 58490) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_handle_session_token_change() != 50104) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_handle_web_channel_password_change() != 37893) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_method_firefoxaccount_has_scope() != 8682) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_constructor_firefoxaccount_new() != 714) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_fxa_client_checksum_constructor_firefoxaccount_from_json() != 60229) {
return InitializationResult.apiChecksumMismatch
}
uniffiEnsureSync15Initialized()
return InitializationResult.ok
}()
// Make the ensure init function public so that other modules which have external type references to
// our types can call it.
public func uniffiEnsureFxaClientInitialized() {
switch initializationResult {
case .ok:
break
case .contractVersionMismatch:
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
case .apiChecksumMismatch:
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}
// swiftlint:enable all