mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 18:40:00 +08:00
feat(ios): update js subscription api (#13678)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added on-demand subscription refresh and state retrieval in the iOS app, enabling up-to-date subscription status and billing information. - Exposed lightweight runtime APIs to check and update subscription state for improved account visibility. - Chores - Integrated shared GraphQL package and project references to support subscription operations. - Updated workspace configuration to include the common GraphQL module for the iOS app. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
|||||||
|
// @generated
|
||||||
|
// This file was automatically generated and should not be edited.
|
||||||
|
|
||||||
|
@_exported import ApolloAPI
|
||||||
|
|
||||||
|
public class RefreshSubscriptionMutation: GraphQLMutation {
|
||||||
|
public static let operationName: String = "refreshSubscription"
|
||||||
|
public static let operationDocument: ApolloAPI.OperationDocument = .init(
|
||||||
|
definition: .init(
|
||||||
|
#"mutation refreshSubscription { refreshUserSubscriptions { __typename id status plan recurring start end nextBillAt canceledAt variant } }"#
|
||||||
|
))
|
||||||
|
|
||||||
|
public init() {}
|
||||||
|
|
||||||
|
public struct Data: AffineGraphQL.SelectionSet {
|
||||||
|
public let __data: DataDict
|
||||||
|
public init(_dataDict: DataDict) { __data = _dataDict }
|
||||||
|
|
||||||
|
public static var __parentType: any ApolloAPI.ParentType { AffineGraphQL.Objects.Mutation }
|
||||||
|
public static var __selections: [ApolloAPI.Selection] { [
|
||||||
|
.field("refreshUserSubscriptions", [RefreshUserSubscription].self),
|
||||||
|
] }
|
||||||
|
|
||||||
|
/// Refresh current user subscriptions and return latest.
|
||||||
|
public var refreshUserSubscriptions: [RefreshUserSubscription] { __data["refreshUserSubscriptions"] }
|
||||||
|
|
||||||
|
/// RefreshUserSubscription
|
||||||
|
///
|
||||||
|
/// Parent Type: `SubscriptionType`
|
||||||
|
public struct RefreshUserSubscription: AffineGraphQL.SelectionSet {
|
||||||
|
public let __data: DataDict
|
||||||
|
public init(_dataDict: DataDict) { __data = _dataDict }
|
||||||
|
|
||||||
|
public static var __parentType: any ApolloAPI.ParentType { AffineGraphQL.Objects.SubscriptionType }
|
||||||
|
public static var __selections: [ApolloAPI.Selection] { [
|
||||||
|
.field("__typename", String.self),
|
||||||
|
.field("id", String?.self),
|
||||||
|
.field("status", GraphQLEnum<AffineGraphQL.SubscriptionStatus>.self),
|
||||||
|
.field("plan", GraphQLEnum<AffineGraphQL.SubscriptionPlan>.self),
|
||||||
|
.field("recurring", GraphQLEnum<AffineGraphQL.SubscriptionRecurring>.self),
|
||||||
|
.field("start", AffineGraphQL.DateTime.self),
|
||||||
|
.field("end", AffineGraphQL.DateTime?.self),
|
||||||
|
.field("nextBillAt", AffineGraphQL.DateTime?.self),
|
||||||
|
.field("canceledAt", AffineGraphQL.DateTime?.self),
|
||||||
|
.field("variant", GraphQLEnum<AffineGraphQL.SubscriptionVariant>?.self),
|
||||||
|
] }
|
||||||
|
|
||||||
|
@available(*, deprecated, message: "removed")
|
||||||
|
public var id: String? { __data["id"] }
|
||||||
|
public var status: GraphQLEnum<AffineGraphQL.SubscriptionStatus> { __data["status"] }
|
||||||
|
/// The 'Free' plan just exists to be a placeholder and for the type convenience of frontend.
|
||||||
|
/// There won't actually be a subscription with plan 'Free'
|
||||||
|
public var plan: GraphQLEnum<AffineGraphQL.SubscriptionPlan> { __data["plan"] }
|
||||||
|
public var recurring: GraphQLEnum<AffineGraphQL.SubscriptionRecurring> { __data["recurring"] }
|
||||||
|
public var start: AffineGraphQL.DateTime { __data["start"] }
|
||||||
|
public var end: AffineGraphQL.DateTime? { __data["end"] }
|
||||||
|
public var nextBillAt: AffineGraphQL.DateTime? { __data["nextBillAt"] }
|
||||||
|
public var canceledAt: AffineGraphQL.DateTime? { __data["canceledAt"] }
|
||||||
|
public var variant: GraphQLEnum<AffineGraphQL.SubscriptionVariant>? { __data["variant"] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
"@affine/component": "workspace:*",
|
"@affine/component": "workspace:*",
|
||||||
"@affine/core": "workspace:*",
|
"@affine/core": "workspace:*",
|
||||||
"@affine/env": "workspace:*",
|
"@affine/env": "workspace:*",
|
||||||
|
"@affine/graphql": "workspace:*",
|
||||||
"@affine/i18n": "workspace:*",
|
"@affine/i18n": "workspace:*",
|
||||||
"@affine/nbstore": "workspace:*",
|
"@affine/nbstore": "workspace:*",
|
||||||
"@blocksuite/affine": "workspace:*",
|
"@blocksuite/affine": "workspace:*",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
ServerScope,
|
ServerScope,
|
||||||
ServerService,
|
ServerService,
|
||||||
ServersService,
|
ServersService,
|
||||||
|
SubscriptionService,
|
||||||
ValidatorProvider,
|
ValidatorProvider,
|
||||||
} from '@affine/core/modules/cloud';
|
} from '@affine/core/modules/cloud';
|
||||||
import { DocsService } from '@affine/core/modules/doc';
|
import { DocsService } from '@affine/core/modules/doc';
|
||||||
@@ -38,6 +39,7 @@ import {
|
|||||||
} from '@affine/core/modules/workspace';
|
} from '@affine/core/modules/workspace';
|
||||||
import { configureBrowserWorkspaceFlavours } from '@affine/core/modules/workspace-engine';
|
import { configureBrowserWorkspaceFlavours } from '@affine/core/modules/workspace-engine';
|
||||||
import { getWorkerUrl } from '@affine/env/worker';
|
import { getWorkerUrl } from '@affine/env/worker';
|
||||||
|
import { refreshSubscriptionMutation } from '@affine/graphql';
|
||||||
import { I18n } from '@affine/i18n';
|
import { I18n } from '@affine/i18n';
|
||||||
import { StoreManagerClient } from '@affine/nbstore/worker/client';
|
import { StoreManagerClient } from '@affine/nbstore/worker/client';
|
||||||
import { Container } from '@blocksuite/affine/global/di';
|
import { Container } from '@blocksuite/affine/global/di';
|
||||||
@@ -328,6 +330,37 @@ const frameworkProvider = framework.provider();
|
|||||||
workspaceRef?.dispose();
|
workspaceRef?.dispose();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
(window as any).getSubscriptionState = async () => {
|
||||||
|
const globalContextService = frameworkProvider.get(GlobalContextService);
|
||||||
|
const currentServerId = globalContextService.globalContext.serverId.get();
|
||||||
|
const serversService = frameworkProvider.get(ServersService);
|
||||||
|
const defaultServerService = frameworkProvider.get(DefaultServerService);
|
||||||
|
const currentServer =
|
||||||
|
(currentServerId ? serversService.server$(currentServerId).value : null) ??
|
||||||
|
defaultServerService.server;
|
||||||
|
const subscriptionService = currentServer.scope.get(SubscriptionService);
|
||||||
|
await subscriptionService.subscription.waitForRevalidation();
|
||||||
|
return {
|
||||||
|
pro: subscriptionService.subscription.pro$.value,
|
||||||
|
ai: subscriptionService.subscription.ai$.value,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
(window as any).updateSubscriptionState = async () => {
|
||||||
|
const globalContextService = frameworkProvider.get(GlobalContextService);
|
||||||
|
const currentServerId = globalContextService.globalContext.serverId.get();
|
||||||
|
const serversService = frameworkProvider.get(ServersService);
|
||||||
|
const defaultServerService = frameworkProvider.get(DefaultServerService);
|
||||||
|
const currentServer =
|
||||||
|
(currentServerId ? serversService.server$(currentServerId).value : null) ??
|
||||||
|
defaultServerService.server;
|
||||||
|
await currentServer
|
||||||
|
.gql({
|
||||||
|
query: refreshSubscriptionMutation,
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
const subscriptionService = currentServer.scope.get(SubscriptionService);
|
||||||
|
subscriptionService.subscription.revalidate();
|
||||||
|
};
|
||||||
|
|
||||||
// setup application lifecycle events, and emit application start event
|
// setup application lifecycle events, and emit application start event
|
||||||
window.addEventListener('focus', () => {
|
window.addEventListener('focus', () => {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
{ "path": "../../component" },
|
{ "path": "../../component" },
|
||||||
{ "path": "../../core" },
|
{ "path": "../../core" },
|
||||||
{ "path": "../../../common/env" },
|
{ "path": "../../../common/env" },
|
||||||
|
{ "path": "../../../common/graphql" },
|
||||||
{ "path": "../../i18n" },
|
{ "path": "../../i18n" },
|
||||||
{ "path": "../../../common/nbstore" },
|
{ "path": "../../../common/nbstore" },
|
||||||
{ "path": "../../../../blocksuite/affine/all" },
|
{ "path": "../../../../blocksuite/affine/all" },
|
||||||
|
|||||||
@@ -1287,6 +1287,7 @@ export const PackageList = [
|
|||||||
'packages/frontend/component',
|
'packages/frontend/component',
|
||||||
'packages/frontend/core',
|
'packages/frontend/core',
|
||||||
'packages/common/env',
|
'packages/common/env',
|
||||||
|
'packages/common/graphql',
|
||||||
'packages/frontend/i18n',
|
'packages/frontend/i18n',
|
||||||
'packages/common/nbstore',
|
'packages/common/nbstore',
|
||||||
'blocksuite/affine/all',
|
'blocksuite/affine/all',
|
||||||
|
|||||||
@@ -682,6 +682,7 @@ __metadata:
|
|||||||
"@affine/component": "workspace:*"
|
"@affine/component": "workspace:*"
|
||||||
"@affine/core": "workspace:*"
|
"@affine/core": "workspace:*"
|
||||||
"@affine/env": "workspace:*"
|
"@affine/env": "workspace:*"
|
||||||
|
"@affine/graphql": "workspace:*"
|
||||||
"@affine/i18n": "workspace:*"
|
"@affine/i18n": "workspace:*"
|
||||||
"@affine/native": "workspace:*"
|
"@affine/native": "workspace:*"
|
||||||
"@affine/nbstore": "workspace:*"
|
"@affine/nbstore": "workspace:*"
|
||||||
|
|||||||
Reference in New Issue
Block a user