Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deferred installation #122

Merged
merged 6 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

### Added
- `provideMemproofs` endpoint
- `allowEmailPasswordAuth` authOpts fields
- `hasMemproofs` field in `AgentState`
- `websdk_version` is now passed with authOpts to chaperone

### Removed
- chaperone version check

## [0.6.19-prerelease] - 2024-03-26

### Updated
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"@holo-host/comb": "0.3.2",
"@holochain/client": "0.16.10",
"@holochain/client": "^0.18.0-dev.2",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"semver": "^7.5.1",
Expand Down
48 changes: 26 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Emittery from "emittery"
import semverSatisfies from 'semver/functions/satisfies'
import { AppInfoResponse, AppAgentClient, AppAgentCallZomeRequest, AppCreateCloneCellRequest, CreateCloneCellResponse, AgentPubKey, AppEnableCloneCellRequest, AppDisableCloneCellRequest, EnableCloneCellResponse, DisableCloneCellResponse, AppSignal, decodeHashFromBase64, NetworkInfoResponse, AppAgentNetworkInfoRequest } from '@holochain/client'

const COMPATIBLE_CHAPERONE_VERSION = '>=0.1.1 <0.3.0'
import {
AppInfoResponse, AppClient, AppCallZomeRequest, AppCreateCloneCellRequest, CreateCloneCellResponse, AgentPubKey, AppEnableCloneCellRequest,
AppDisableCloneCellRequest, EnableCloneCellResponse, DisableCloneCellResponse, AppSignal, decodeHashFromBase64, NetworkInfoResponse, NetworkInfoRequest,
ProvideMemproofsRequest,
ProvideMemproofsResponse
} from '@holochain/client'

const TESTING = (<any>global).COMB !== undefined
if (!TESTING) {
Expand All @@ -13,19 +15,11 @@ function makeUrlAbsolute (url) {
return new URL(url, window.location.href).href
}

function checkChaperoneVersion (chaperoneVersion) {
const isSatisfied = semverSatisfies(chaperoneVersion, COMPATIBLE_CHAPERONE_VERSION)

if (!isSatisfied) {
console.error(`!!!!! WARNING: you are connecting to an unsupported version of Chaperone. Expected version matching: ${COMPATIBLE_CHAPERONE_VERSION}. Actual version: ${chaperoneVersion} !!!!!`)
}
}

/**
* A `WebSdkApi` is a connection to a Chaperone iframe containing Holo's client logic.
* @param child - The child process connecting to Chaperone that is being monitored.
*/
class WebSdkApi implements AppAgentClient {
class WebSdkApi implements AppClient {
// Private constructor. Use `connect` instead.
#child: any;
agentState: AgentState;
Expand All @@ -37,6 +31,7 @@ class WebSdkApi implements AppAgentClient {
#cancellable: boolean;
#emitter = new Emittery();
myPubKey: AgentPubKey;
installedAppId: string; // this is to conform with the `AppClient` interface and as never used in web-sdk

constructor (child) {
this.#child = child
Expand Down Expand Up @@ -73,6 +68,8 @@ class WebSdkApi implements AppAgentClient {
}: { chaperoneUrl: string, authFormCustomization?: AuthFormCustomization }) => {
const url = new URL(chaperoneUrl || 'https://chaperone.holo.hosting')

url.searchParams.set('websdk_version', process.env.VERSION)

if (authOpts !== undefined) {
if (authOpts.logoUrl !== undefined) {
url.searchParams.set('logo_url', makeUrlAbsolute(authOpts.logoUrl))
Expand All @@ -96,17 +93,22 @@ class WebSdkApi implements AppAgentClient {
if (authOpts.requireRegistrationCode !== undefined) {
url.searchParams.set('require_registration_code', String(authOpts.requireRegistrationCode))
}

if (authOpts.integrationTestMode !== undefined) {
url.searchParams.set('integration_test_mode', String(authOpts.integrationTestMode))
}

if (authOpts.allowEmailPasswordAuth !== undefined) {
url.searchParams.set('allow_email_password_auth', String(authOpts.allowEmailPasswordAuth))
}

// INTERNAL OPTION
// anonymous_allowed is barely implemented in Chaperone, and is subject to change,
// so exposing this in the documentation is misleading.
// This is currently useful for some special hApps that can't support an anonymous instance.
if (authOpts.anonymousAllowed !== undefined) {
url.searchParams.set('anonymous_allowed', String(authOpts.anonymousAllowed))
}

if (authOpts.integrationTestMode !== undefined) {
url.searchParams.set('integration_test_mode', String(authOpts.integrationTestMode))
}
}

let child
Expand Down Expand Up @@ -146,12 +148,10 @@ class WebSdkApi implements AppAgentClient {

// Chaperone either returns agent_state and happ_id (success case)
// or error_message
const { error_message, chaperone_state, happ_id, chaperone_version } = await child.call(
const { error_message, chaperone_state, happ_id } = await child.call(
'handshake'
)

checkChaperoneVersion(chaperone_version)

if (error_message) {
webSdkApi.#iframe.style.display = 'none'
throw new Error(error_message)
Expand Down Expand Up @@ -192,16 +192,18 @@ class WebSdkApi implements AppAgentClient {

appInfo = (): Promise<AppInfoResponse> => this.#child.call('appInfo')

networkInfo = (args: AppAgentNetworkInfoRequest): Promise<NetworkInfoResponse> => this.#child.call('networkInfo', args)
networkInfo = (args: NetworkInfoRequest): Promise<NetworkInfoResponse> => this.#child.call('networkInfo', args)

callZome = async (args: AppAgentCallZomeRequest): Promise<any> => this.#child.call('callZome', args).then(unwrap)
callZome = async (args: AppCallZomeRequest): Promise<any> => this.#child.call('callZome', args).then(unwrap)

createCloneCell = (args: AppCreateCloneCellRequest): Promise<CreateCloneCellResponse> => this.#child.call('createCloneCell', args).then(unwrap)

disableCloneCell = (args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse> => this.#child.call('disableCloneCell', args).then(unwrap)

enableCloneCell = (args: AppEnableCloneCellRequest): Promise<EnableCloneCellResponse> => this.#child.call('enableCloneCell', args).then(unwrap)

provideMemproofs = (args: ProvideMemproofsRequest): Promise<ProvideMemproofsResponse> => this.#child.call('provideMemproofs', args).then(unwrap)

signPayload = (args: any): Promise<any> => this.#child.call('signPayload', args).then(unwrap)

stateDump = () => this.#child.call('stateDump')
Expand Down Expand Up @@ -252,6 +254,7 @@ export type AgentState = {
isAnonymous: boolean
hostUrl: string
isAvailable: boolean
hasMemproofs: boolean
unrecoverableError: any
}

Expand All @@ -270,6 +273,7 @@ export type ChaperoneState = {
// DUPLICATION END

type AuthFormCustomization = {
allowEmailPasswordAuth?: boolean
// The name of the hosted hApp. Currently shows up as "appName Login"
appName?: string
// The URL of the hApp logo. Currently displayed on a white background with no `width` or `height` constraints.
Expand Down
8 changes: 8 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const PACKAGE = require('./package.json')
const webpack = require('webpack')

module.exports = {
target: "web",
mode: 'development', // production | development
Expand Down Expand Up @@ -41,5 +44,10 @@ module.exports = {
},

plugins: [
new webpack.DefinePlugin({
'process.env':{
'VERSION': `'${PACKAGE.version}'`,
},
}),
],
};
26 changes: 10 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1153,15 +1153,14 @@
resolved "https://registry.yarnpkg.com/@holo-host/wasm-key-manager/-/wasm-key-manager-1.0.0.tgz#32e5365ddc4518a01c17d2aba09d11bf3a042429"
integrity sha512-GTfeQ2iYvYYrIkuaF0QupWP/y8sdItwL6Tr1osyaU7eUsWtGfpZqDcTZny8KNDdnQAEEP2nDWZORA/Z3EMJa3w==

"@holochain/client@0.16.10":
version "0.16.10"
resolved "https://registry.yarnpkg.com/@holochain/client/-/client-0.16.10.tgz#7ef9019922edfea4ceda7bb8d3eaae7beddc98e3"
integrity sha512-Urgx6vXNux2XD/4+eOxou2FKwlUBu/g/BxUSZLX6wEaYWH9wDYXR5f3VToUrAhXGF5ssc08jb8jLiQZ23k62EQ==
"@holochain/client@^0.18.0-dev.2":
version "0.18.0-dev.2"
resolved "https://registry.yarnpkg.com/@holochain/client/-/client-0.18.0-dev.2.tgz#59d39060b1b258e2cebcab39b87f6fabd54ea75a"
integrity sha512-SpmGdmyRZlWg9TBoXCdqoU65xb7ScpWXYpTwnTu8Ppe43Q+KbFzgTBlpsWNJI28hIVDEWh0I9xVS4kNPKa4plw==
dependencies:
"@bitgo/blake2b" "^3.2.4"
"@holochain/serialization" "^0.1.0-beta-rc.3"
"@msgpack/msgpack" "^2.8.0"
"@tauri-apps/api" "^1.4.0"
emittery "^1.0.1"
isomorphic-ws "^5.0.0"
js-base64 "^3.7.5"
Expand Down Expand Up @@ -1284,11 +1283,6 @@
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==

"@tauri-apps/api@^1.4.0":
version "1.5.3"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.5.3.tgz#f7b362b1f30aadb0a8bbeb7ae111755c0ed33d73"
integrity sha512-zxnDjHHKjOsrIzZm6nO5Xapb/BxqUq1tc7cGkFXsFkGTsSWgCPH1D8mm0XS9weJY2OaR73I3k3S+b7eSzJDfqA==

"@tootallnate/once@2":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
Expand Down Expand Up @@ -2402,9 +2396,9 @@ elliptic@^6.5.3, elliptic@^6.5.5:
minimalistic-crypto-utils "^1.0.1"

emittery@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/emittery/-/emittery-1.0.1.tgz#e0cf36e2d7eef94dbd025969f642d57ae50a56cd"
integrity sha512-2ID6FdrMD9KDLldGesP6317G78K7km/kMcwItRtVFva7I/cSEOIaLpewaUb+YLXVwdAp3Ctfxh/V5zIl1sj7dQ==
version "1.0.3"
resolved "https://registry.yarnpkg.com/emittery/-/emittery-1.0.3.tgz#c9d2a9c689870f15251bb13b31c67715c26d69ac"
integrity sha512-tJdCJitoy2lrC2ldJcqN4vkqJ00lT+tOWNT1hBJjO/3FDMJa5TTIiYGCKGkn/WfCyOzUMObeohbVTj00fhiLiA==

emojis-list@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -4302,9 +4296,9 @@ ws@^8.13.0:
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==

ws@^8.14.2:
version "8.16.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4"
integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==
version "8.17.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.0.tgz#d145d18eca2ed25aaf791a183903f7be5e295fea"
integrity sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==

xml-name-validator@^4.0.0:
version "4.0.0"
Expand Down
Loading