mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 14:08:55 +08:00
feat: init ios-bridge
This commit is contained in:
@@ -129,23 +129,13 @@ export class AuthService extends Service {
|
||||
}
|
||||
|
||||
async signInPassword(credential: { email: string; password: string }) {
|
||||
const searchParams = new URLSearchParams();
|
||||
const redirectUri = new URL(location.href);
|
||||
if (environment.isDesktop) {
|
||||
redirectUri.pathname = this.buildRedirectUri('/open-app/signin-redirect');
|
||||
}
|
||||
searchParams.set('redirect_uri', redirectUri.toString());
|
||||
|
||||
const res = await this.fetchService.fetch(
|
||||
'/api/auth/sign-in?' + searchParams.toString(),
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify(credential),
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
}
|
||||
);
|
||||
const res = await this.fetchService.fetch('/api/auth/sign-in', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(credential),
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error('Failed to sign in');
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import { fromPromise, Service } from '@toeverything/infra';
|
||||
import { BackendError, NetworkError } from '../error';
|
||||
|
||||
export function getAffineCloudBaseUrl(): string {
|
||||
if ((globalThis as any)['__AFFINE_CLOUD_BASE_URL__']) {
|
||||
return (globalThis as any)['__AFFINE_CLOUD_BASE_URL__'];
|
||||
}
|
||||
if (environment.isDesktop) {
|
||||
return runtimeConfig.serverUrlPrefix;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ import { gqlFetcherFactory } from './fetcher';
|
||||
setupGlobal();
|
||||
|
||||
export function getBaseUrl(): string {
|
||||
if ((globalThis as any)['__AFFINE_CLOUD_BASE_URL__']) {
|
||||
return (globalThis as any)['__AFFINE_CLOUD_BASE_URL__'];
|
||||
}
|
||||
if (environment.isDesktop) {
|
||||
return runtimeConfig.serverUrlPrefix;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "@affine/ios-bridge",
|
||||
"version": "0.0.0",
|
||||
"description": "AFFiNE API For iOS app",
|
||||
"private": true,
|
||||
"browser": "src/index.ts",
|
||||
"scripts": {
|
||||
"build": "DISTRIBUTION=ios-bridge yarn workspace @affine/cli build",
|
||||
"dev": "DISTRIBUTION=ios-bridge yarn workspace @affine/cli dev",
|
||||
"static-server": "DISTRIBUTION=ios-bridge yarn workspace @affine/cli dev --static"
|
||||
},
|
||||
"dependencies": {
|
||||
"@affine/core": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@sentry/react": "^7.109.0",
|
||||
"core-js": "^3.36.1",
|
||||
"intl-segmenter-polyfill-rs": "^0.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@affine/cli": "workspace:*",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import './polyfill/dispose';
|
||||
import './polyfill/intl-segmenter';
|
||||
import './polyfill/request-idle-callback';
|
||||
import '@affine/core/bootstrap/preload';
|
||||
|
||||
import { configureCommonModules } from '@affine/core/modules';
|
||||
import { AuthService } from '@affine/core/modules/cloud';
|
||||
import { configureLocalStorageStateStorageImpls } from '@affine/core/modules/storage';
|
||||
import {
|
||||
configureBrowserWorkspaceFlavours,
|
||||
configureIndexedDBWorkspaceEngineStorageProvider,
|
||||
} from '@affine/core/modules/workspace-engine';
|
||||
import {
|
||||
DocsService,
|
||||
Framework,
|
||||
LifecycleService,
|
||||
type WorkspaceMetadata,
|
||||
WorkspacesService,
|
||||
} from '@toeverything/infra';
|
||||
|
||||
const framework = new Framework();
|
||||
configureCommonModules(framework);
|
||||
configureLocalStorageStateStorageImpls(framework);
|
||||
configureBrowserWorkspaceFlavours(framework);
|
||||
configureIndexedDBWorkspaceEngineStorageProvider(framework);
|
||||
const frameworkProvider = framework.provider();
|
||||
|
||||
// start the application
|
||||
frameworkProvider.get(LifecycleService).applicationStart();
|
||||
|
||||
const jsb = {
|
||||
signInPassword(email: string, password: string) {
|
||||
return frameworkProvider
|
||||
.get(AuthService)
|
||||
.signInPassword({ email, password });
|
||||
},
|
||||
|
||||
getWorkspacesList() {
|
||||
return frameworkProvider.get(WorkspacesService).list.workspaces$;
|
||||
},
|
||||
|
||||
getWorkspacesDocs(workspaceMeta: WorkspaceMetadata) {
|
||||
return frameworkProvider
|
||||
.get(WorkspacesService)
|
||||
.open({ metadata: workspaceMeta })
|
||||
.workspace.scope.get(DocsService)
|
||||
.list.docs$.map(docs => docs.map(d => d.meta$.value));
|
||||
},
|
||||
// ... add more methods here
|
||||
};
|
||||
|
||||
(window as any).jsb = jsb;
|
||||
(window as any).workspacesService = frameworkProvider.get(WorkspacesService);
|
||||
@@ -0,0 +1,2 @@
|
||||
import 'core-js/modules/esnext.symbol.async-dispose';
|
||||
import 'core-js/modules/esnext.symbol.dispose';
|
||||
@@ -0,0 +1,11 @@
|
||||
if (Intl.Segmenter === undefined) {
|
||||
await import('intl-segmenter-polyfill-rs').then(({ Segmenter }) => {
|
||||
Object.defineProperty(Intl, 'Segmenter', {
|
||||
value: Segmenter,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,19 @@
|
||||
window.requestIdleCallback =
|
||||
window.requestIdleCallback ||
|
||||
function (cb) {
|
||||
const start = Date.now();
|
||||
return setTimeout(function () {
|
||||
cb({
|
||||
didTimeout: false,
|
||||
timeRemaining: function () {
|
||||
return Math.max(0, 50 - (Date.now() - start));
|
||||
},
|
||||
});
|
||||
}, 1);
|
||||
};
|
||||
|
||||
window.cancelIdleCallback =
|
||||
window.cancelIdleCallback ||
|
||||
function (id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"outDir": "lib",
|
||||
"moduleResolution": "Bundler",
|
||||
"types": ["affine__env"],
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"include": ["./src"],
|
||||
"references": [{ "path": "../core" }]
|
||||
}
|
||||
Reference in New Issue
Block a user