@jsb188/graphql 1.1.10 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audience.d.ts +343 -0
- package/cache/config.ts +98 -50
- package/cache/index.chat-activity.test.ts +119 -0
- package/cache/index.chat.test.ts +92 -0
- package/cache/index.helpers.ts +96 -0
- package/cache/index.regression.test.ts +149 -0
- package/cache/index.test.ts +1017 -127
- package/cache/index.ts +1256 -1269
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +800 -0
- package/cache/store.ts +395 -0
- package/cache/value.helpers.ts +17 -0
- package/client/draft-persistence-indexed-db.ts +413 -0
- package/client/draft-persistence.ts +152 -0
- package/client/index.ts +3 -0
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +870 -164
- package/deno.lock +187 -0
- package/deno.test.json +10 -4
- package/gql/eagerQueryMap.ts +12 -0
- package/gql/fragments/accountAuthFragments.ts +5 -0
- package/gql/fragments/accountFragments.ts +0 -3
- package/gql/fragments/accountSessionFragments.ts +16 -0
- package/gql/fragments/agentMemoryFragments.ts +23 -0
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +42 -0
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +566 -0
- package/gql/fragments/dataTableFragments.ts +50 -192
- package/gql/fragments/emailFragments.ts +32 -17
- package/gql/fragments/fieldDocFragments.ts +264 -0
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +101 -69
- package/gql/fragments/organizationFragments.ts +53 -5
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +667 -0
- package/gql/fragments/sheetFragments.ts +304 -63
- package/gql/fragments/storageFragments.ts +45 -0
- package/gql/fragments/workflowFragments.ts +41 -5
- package/gql/mutations/accountMutations.ts +0 -2
- package/gql/mutations/agentMemoryMutations.ts +68 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +49 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +203 -18
- package/gql/mutations/billingMutations.ts +17 -27
- package/gql/mutations/campaignMutations.ts +258 -0
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +19 -54
- package/gql/mutations/fieldDocMutations.ts +173 -0
- package/gql/mutations/index.ts +10 -2
- package/gql/mutations/logMutations.ts +6 -29
- package/gql/mutations/organizationMutations.ts +19 -4
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1121 -0
- package/gql/mutations/sheetMutations.ts +221 -60
- package/gql/mutations/storageMutations.ts +19 -0
- package/gql/mutations/workflowMutations.ts +60 -0
- package/gql/queries/agentMemoryQueries.ts +28 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +70 -2
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +47 -0
- package/gql/queries/billingQueries.ts +118 -6
- package/gql/queries/campaignQueries.ts +236 -0
- package/gql/queries/dataTableQueries.ts +61 -13
- package/gql/queries/emailQueries.ts +26 -17
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +166 -0
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +10 -2
- package/gql/queries/logQueries.ts +68 -30
- package/gql/queries/organizationQueries.ts +65 -1
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +691 -0
- package/gql/queries/sheetQueries.ts +244 -26
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +77 -2
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +2254 -982
- package/hooks/use-account-mtn.ts +76 -81
- package/hooks/use-agentMemory-mtn.ts +71 -0
- package/hooks/use-agentMemory-qry.ts +56 -0
- package/hooks/use-agentNote-mtn.ts +82 -0
- package/hooks/use-agentNote-qry.ts +190 -0
- package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +72 -0
- package/hooks/use-aiChat-mtn.ts +220 -141
- package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +341 -237
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-app-qry.ts +12 -9
- package/hooks/use-audience-mtn.ts +194 -0
- package/hooks/use-audience-qry.helpers.test.ts +80 -0
- package/hooks/use-audience-qry.helpers.ts +63 -0
- package/hooks/use-audience-qry.ts +330 -0
- package/hooks/use-auth-mtn.ts +435 -252
- package/hooks/use-auth-qry.ts +51 -0
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-campaign-generation-recovery.ts +53 -0
- package/hooks/use-campaign-mtn.ts +436 -0
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +834 -0
- package/hooks/use-dataTable-mtn.ts +37 -46
- package/hooks/use-dataTable-qry.ts +102 -128
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +56 -86
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +262 -0
- package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +212 -0
- package/hooks/use-inboundContact-mtn.ts +19 -16
- package/hooks/use-inboundContact-qry.ts +62 -56
- package/hooks/use-integration-mtn.ts +56 -38
- package/hooks/use-integration-qry.ts +24 -9
- package/hooks/use-log-mtn.ts +88 -59
- package/hooks/use-log-qry.ts +150 -73
- package/hooks/use-organization-mtn.ts +334 -277
- package/hooks/use-organization-qry.ts +155 -129
- package/hooks/use-publicFormEmail-mtn.ts +27 -0
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +589 -0
- package/hooks/use-schedule-qry.ts +738 -0
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +157 -79
- package/hooks/use-sheet-qry.ts +221 -92
- package/hooks/use-storage-mtn.ts +81 -41
- package/hooks/use-storage-qry.ts +128 -14
- package/hooks/use-workflow-mtn.ts +72 -0
- package/hooks/use-workflow-qry.ts +184 -47
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/fragment-recovery.test.ts +326 -0
- package/libs/fragment-recovery.ts +325 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/orchestrator-realtime.helpers.test.ts +229 -0
- package/libs/orchestrator-realtime.helpers.ts +317 -0
- package/libs/orchestrator-realtime.ts +433 -0
- package/libs/request-cache-regression.test.ts +122 -0
- package/libs/request-managed-session.test.ts +574 -0
- package/libs/request-no-store.test.ts +419 -0
- package/libs/sheet-command-batch.ts +44 -0
- package/libs/sheet-view-realtime-router.test.ts +214 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/libs/sse-ticket.test.ts +26 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +110 -0
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +119 -71
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +70 -106
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/tsconfig.json +11 -10
- package/types.d.ts +77 -26
- package/utils.ts +78 -49
- package/gql/fragments/billingFragments.ts +0 -25
- package/gql/fragments/productFragments.ts +0 -39
- package/gql/fragments/reportFragments.ts +0 -90
- package/gql/queries/productQueries.ts +0 -31
- package/gql/queries/reportQueries.ts +0 -134
- package/hooks/use-product-qry.ts +0 -67
- package/hooks/use-report-qry.ts +0 -153
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FRAGMENT_NAMES,
|
|
3
|
+
getFragmentBaseName,
|
|
4
|
+
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
5
|
+
import { useReactiveFragmentMap } from '../client/index.ts';
|
|
6
|
+
import {
|
|
7
|
+
myAccountSessionsQry,
|
|
8
|
+
organizationMemberSessionsQry,
|
|
9
|
+
} from '../gql/queries/authQueries.ts';
|
|
10
|
+
import { useQuery } from './index.ts';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Load and reactively observe the current account's managed sessions.
|
|
14
|
+
*/
|
|
15
|
+
export function useMyAccountSessions() {
|
|
16
|
+
const query = useQuery(myAccountSessionsQry);
|
|
17
|
+
const sessions = useReactiveFragmentMap(
|
|
18
|
+
query.data?.myAccountSessions || null,
|
|
19
|
+
getFragmentBaseName(FRAGMENT_NAMES.accountSession),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
...query,
|
|
24
|
+
accountSessions: sessions,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* Load and reactively observe one member's sessions visible to an organization administrator.
|
|
30
|
+
*/
|
|
31
|
+
export function useOrganizationMemberSessions(
|
|
32
|
+
organizationId?: string | null,
|
|
33
|
+
accountId?: string | null,
|
|
34
|
+
) {
|
|
35
|
+
const query = useQuery(organizationMemberSessionsQry, {
|
|
36
|
+
variables: {
|
|
37
|
+
organizationId,
|
|
38
|
+
accountId,
|
|
39
|
+
},
|
|
40
|
+
skip: !organizationId || !accountId,
|
|
41
|
+
});
|
|
42
|
+
const sessions = useReactiveFragmentMap(
|
|
43
|
+
query.data?.organizationMemberSessions || null,
|
|
44
|
+
getFragmentBaseName(FRAGMENT_NAMES.accountSession),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
...query,
|
|
49
|
+
accountSessions: sessions,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import { startBillingSubscriptionMtn } from '../gql/mutations/billingMutations.ts';
|
|
3
|
+
import { useMutation } from './index.ts';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Start a self-serve subscription for an organization. The response carries a
|
|
7
|
+
* Stripe client secret, so it is never cached (no-store) and never retried.
|
|
8
|
+
* There is deliberately no openModalPopUp option: the payment pop-up renders
|
|
9
|
+
* errors inline, and opening another pop-up would replace it.
|
|
10
|
+
*/
|
|
11
|
+
export function useStartBillingSubscription(params: UseMutationParams = {}) {
|
|
12
|
+
const { onCompleted, onError } = params;
|
|
13
|
+
|
|
14
|
+
const [startBillingSubscription, mtnValues, mtnHandlers] = useMutation(
|
|
15
|
+
startBillingSubscriptionMtn,
|
|
16
|
+
{
|
|
17
|
+
cachePolicy: 'no-store',
|
|
18
|
+
retryCount: 0,
|
|
19
|
+
onCompleted: (data, error, variables) => {
|
|
20
|
+
onCompleted?.(data?.startBillingSubscription, error, variables);
|
|
21
|
+
},
|
|
22
|
+
onError,
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
startBillingSubscription,
|
|
28
|
+
...mtnValues,
|
|
29
|
+
...mtnHandlers,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useQuery } from '@jsb188/graphql/client';
|
|
2
|
+
import type { BillingAddressInputGQL } from '@jsb188/mday/types/billing.d.ts';
|
|
3
|
+
import {
|
|
4
|
+
billingClientConfigQry,
|
|
5
|
+
billingPlansQry,
|
|
6
|
+
billingPurchasePreviewQry,
|
|
7
|
+
organizationBillingQry,
|
|
8
|
+
} from '../gql/queries/billingQueries.ts';
|
|
9
|
+
import type { UseQueryParams } from '../types.d.ts';
|
|
10
|
+
|
|
11
|
+
export type BillingPurchasePreviewVariables = {
|
|
12
|
+
organizationId?: string | null;
|
|
13
|
+
priceId?: string | null;
|
|
14
|
+
address?: BillingAddressInputGQL | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Fetch the self-serve plans: Basic and Business with their public prices,
|
|
19
|
+
* and Enterprise as a contact-sales plan without prices.
|
|
20
|
+
*/
|
|
21
|
+
export function useBillingPlans(params: UseQueryParams = {}) {
|
|
22
|
+
// The public plan catalog can reuse fresh data; billing state still revalidates on entry.
|
|
23
|
+
const { data, ...rest } = useQuery(billingPlansQry, { revalidateOnMount: false, ...params });
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
billingPlans: data?.billingPlans,
|
|
27
|
+
...rest,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* Fetch the Stripe publishable key and payment method types the payment form
|
|
33
|
+
* must use. The server picks the key, so its mode always matches the secret key.
|
|
34
|
+
*/
|
|
35
|
+
export function useBillingClientConfig(params: UseQueryParams = {}) {
|
|
36
|
+
const { data, ...rest } = useQuery(billingClientConfigQry, params);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
billingClientConfig: data?.billingClientConfig,
|
|
40
|
+
...rest,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Fetch an organization's billing status: access state, current subscription
|
|
46
|
+
* and recent invoices. Skipped until an organization id is known.
|
|
47
|
+
*/
|
|
48
|
+
export function useOrganizationBilling(organizationId: string | null | undefined, params: UseQueryParams = {}) {
|
|
49
|
+
const { data, ...rest } = useQuery(organizationBillingQry, {
|
|
50
|
+
...params,
|
|
51
|
+
variables: { organizationId },
|
|
52
|
+
skip: !organizationId || !!params.skip,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
organizationBilling: data?.organizationBilling,
|
|
57
|
+
...rest,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* Preview the subtotal, tax and total of one plan price for a billing address.
|
|
63
|
+
* Skipped until the organization, price and address are all set.
|
|
64
|
+
*/
|
|
65
|
+
export function useBillingPurchasePreview(variables: BillingPurchasePreviewVariables, params: UseQueryParams = {}) {
|
|
66
|
+
const { data, ...rest } = useQuery(billingPurchasePreviewQry, {
|
|
67
|
+
...params,
|
|
68
|
+
variables,
|
|
69
|
+
skip: !variables.organizationId || !variables.priceId || !variables.address || !!params.skip,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
billingPurchasePreview: data?.billingPurchasePreview,
|
|
74
|
+
...rest,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Recover a pending generation's atomic session when realtime settlement is missed.
|
|
5
|
+
* Keep requests sequential and stop checking when the session settles or unmounts.
|
|
6
|
+
*/
|
|
7
|
+
export function useCampaignGenerationRecovery(p: {
|
|
8
|
+
campaignId?: string | null;
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
generationStatus?: string | null;
|
|
11
|
+
reactiveGenerationStatus?: string | null;
|
|
12
|
+
refetch: () => Promise<unknown>;
|
|
13
|
+
}) {
|
|
14
|
+
const {
|
|
15
|
+
campaignId,
|
|
16
|
+
enabled,
|
|
17
|
+
generationStatus,
|
|
18
|
+
reactiveGenerationStatus,
|
|
19
|
+
refetch,
|
|
20
|
+
} = p;
|
|
21
|
+
const pending =
|
|
22
|
+
generationStatus === 'GENERATING' || generationStatus === 'GENERATED';
|
|
23
|
+
const settled =
|
|
24
|
+
reactiveGenerationStatus === 'GENERATED' ||
|
|
25
|
+
reactiveGenerationStatus === 'COMPLETE' ||
|
|
26
|
+
reactiveGenerationStatus === 'ERROR';
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!enabled || !campaignId || !pending) return;
|
|
30
|
+
let active = true;
|
|
31
|
+
let timer: ReturnType<typeof setTimeout>;
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* Retry reads after settlement races or network failures without overlapping requests.
|
|
35
|
+
*/
|
|
36
|
+
const refresh = async () => {
|
|
37
|
+
try {
|
|
38
|
+
await refetch();
|
|
39
|
+
} catch {
|
|
40
|
+
// The query owns error presentation; keep recovery available while pending.
|
|
41
|
+
} finally {
|
|
42
|
+
if (active) timer = setTimeout(refresh, 10_000);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (settled) void refresh();
|
|
47
|
+
else timer = setTimeout(refresh, 10_000);
|
|
48
|
+
return () => {
|
|
49
|
+
active = false;
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
};
|
|
52
|
+
}, [campaignId, enabled, pending, refetch, settled]);
|
|
53
|
+
}
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
|
+
import {
|
|
4
|
+
archiveCampaignTemplateMtn,
|
|
5
|
+
createCampaignMtn,
|
|
6
|
+
createCampaignTemplateMtn,
|
|
7
|
+
createEmailCampaignDraftMtn,
|
|
8
|
+
createFormCampaignDraftMtn,
|
|
9
|
+
editCampaignMtn,
|
|
10
|
+
editCampaignSettingsMtn,
|
|
11
|
+
editCampaignTemplateMtn,
|
|
12
|
+
finalizeCampaignElementImageUploadMtn,
|
|
13
|
+
finalizeCampaignHeaderImageUploadMtn,
|
|
14
|
+
retryCampaignGenerationMtn,
|
|
15
|
+
sendCampaignEmailMtn,
|
|
16
|
+
sendCampaignTestEmailMtn,
|
|
17
|
+
submitCampaignResponseMtn,
|
|
18
|
+
updateCampaignAccessMtn,
|
|
19
|
+
} from '../gql/mutations/campaignMutations.ts';
|
|
20
|
+
import { useMutation } from './index.ts';
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* Start one AI-generated campaign from an accessible template.
|
|
24
|
+
*
|
|
25
|
+
* Resolves as soon as the GENERATING campaign exists. A later GraphQL-only
|
|
26
|
+
* GENERATED websocket patch tells observers to refetch the finished draft.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export function useCreateCampaign(
|
|
30
|
+
params: UseMutationParams = {},
|
|
31
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
32
|
+
) {
|
|
33
|
+
const { onCompleted, ...rest } = params;
|
|
34
|
+
const [createCampaign, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
35
|
+
createCampaignMtn,
|
|
36
|
+
{
|
|
37
|
+
openModalPopUp,
|
|
38
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
39
|
+
onCompleted?.(data?.createCampaign, error, variables);
|
|
40
|
+
},
|
|
41
|
+
...rest,
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
createCampaign,
|
|
47
|
+
updateObservers,
|
|
48
|
+
...mtnValues,
|
|
49
|
+
...mtnHandlers,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Retry one failed generation. The row returns to GENERATING and settles again
|
|
55
|
+
* over the websocket.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
export function useRetryCampaignGeneration(
|
|
59
|
+
params: UseMutationParams = {},
|
|
60
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
61
|
+
) {
|
|
62
|
+
const { onCompleted, ...rest } = params;
|
|
63
|
+
|
|
64
|
+
const [retryCampaignGeneration, mtnValues, mtnHandlers, updateObservers] =
|
|
65
|
+
useMutation(retryCampaignGenerationMtn, {
|
|
66
|
+
openModalPopUp,
|
|
67
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
68
|
+
onCompleted?.(data?.retryCampaignGeneration, error, variables);
|
|
69
|
+
},
|
|
70
|
+
...rest,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
retryCampaignGeneration,
|
|
75
|
+
updateObservers,
|
|
76
|
+
...mtnValues,
|
|
77
|
+
...mtnHandlers,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* Apply a versioned editor patch to one reusable campaign template.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Create one empty, editable campaign template owned by the organization.
|
|
87
|
+
*/
|
|
88
|
+
export function useCreateCampaignTemplate(
|
|
89
|
+
params: UseMutationParams = {},
|
|
90
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
91
|
+
) {
|
|
92
|
+
const { onCompleted, ...rest } = params;
|
|
93
|
+
const [createCampaignTemplate, mtnValues, mtnHandlers, updateObservers] =
|
|
94
|
+
useMutation(createCampaignTemplateMtn, {
|
|
95
|
+
openModalPopUp,
|
|
96
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
97
|
+
onCompleted?.(data?.createCampaignTemplate, error, variables);
|
|
98
|
+
},
|
|
99
|
+
...rest,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
createCampaignTemplate,
|
|
104
|
+
updateObservers,
|
|
105
|
+
...mtnValues,
|
|
106
|
+
...mtnHandlers,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function useEditCampaignTemplate(
|
|
111
|
+
params: UseMutationParams = {},
|
|
112
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
113
|
+
) {
|
|
114
|
+
const { onCompleted, ...rest } = params;
|
|
115
|
+
|
|
116
|
+
const [editCampaignTemplate, mtnValues, mtnHandlers, updateObservers] =
|
|
117
|
+
useMutation(editCampaignTemplateMtn, {
|
|
118
|
+
openModalPopUp,
|
|
119
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
120
|
+
onCompleted?.(data?.editCampaignTemplate, error, variables);
|
|
121
|
+
},
|
|
122
|
+
...rest,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
editCampaignTemplate,
|
|
127
|
+
updateObservers,
|
|
128
|
+
...mtnValues,
|
|
129
|
+
...mtnHandlers,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
* Apply a versioned editor patch to one campaign.
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
export function useEditCampaign(
|
|
138
|
+
params: UseMutationParams = {},
|
|
139
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
140
|
+
) {
|
|
141
|
+
const { onCompleted, ...rest } = params;
|
|
142
|
+
|
|
143
|
+
const [editCampaign, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
144
|
+
editCampaignMtn,
|
|
145
|
+
{
|
|
146
|
+
openModalPopUp,
|
|
147
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
148
|
+
const result = data?.editCampaign;
|
|
149
|
+
onCompleted?.(result, error, variables);
|
|
150
|
+
},
|
|
151
|
+
...rest,
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
editCampaign,
|
|
157
|
+
updateObservers,
|
|
158
|
+
...mtnValues,
|
|
159
|
+
...mtnHandlers,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
* Finalize one uploaded campaign header image before an editor links it.
|
|
165
|
+
*/
|
|
166
|
+
export function useFinalizeCampaignHeaderImageUpload(
|
|
167
|
+
params: UseMutationParams = {},
|
|
168
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
169
|
+
) {
|
|
170
|
+
const { onCompleted, ...rest } = params;
|
|
171
|
+
const [
|
|
172
|
+
finalizeCampaignHeaderImageUpload,
|
|
173
|
+
mtnValues,
|
|
174
|
+
mtnHandlers,
|
|
175
|
+
updateObservers,
|
|
176
|
+
] = useMutation(finalizeCampaignHeaderImageUploadMtn, {
|
|
177
|
+
openModalPopUp,
|
|
178
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
179
|
+
onCompleted?.(data?.finalizeCampaignHeaderImageUpload, error, variables);
|
|
180
|
+
},
|
|
181
|
+
...rest,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
finalizeCampaignHeaderImageUpload,
|
|
186
|
+
updateObservers,
|
|
187
|
+
...mtnValues,
|
|
188
|
+
...mtnHandlers,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/*
|
|
193
|
+
* Finalize one uploaded campaign element image before an editor links it.
|
|
194
|
+
*/
|
|
195
|
+
export function useFinalizeCampaignElementImageUpload(
|
|
196
|
+
params: UseMutationParams = {},
|
|
197
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
198
|
+
) {
|
|
199
|
+
const { onCompleted, ...rest } = params;
|
|
200
|
+
const [
|
|
201
|
+
finalizeCampaignElementImageUpload,
|
|
202
|
+
mtnValues,
|
|
203
|
+
mtnHandlers,
|
|
204
|
+
updateObservers,
|
|
205
|
+
] = useMutation(finalizeCampaignElementImageUploadMtn, {
|
|
206
|
+
openModalPopUp,
|
|
207
|
+
/*
|
|
208
|
+
* Unwrap the finalized element image payload for hook consumers.
|
|
209
|
+
*/
|
|
210
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
211
|
+
onCompleted?.(data?.finalizeCampaignElementImageUpload, error, variables);
|
|
212
|
+
},
|
|
213
|
+
...rest,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
finalizeCampaignElementImageUpload,
|
|
218
|
+
updateObservers,
|
|
219
|
+
...mtnValues,
|
|
220
|
+
...mtnHandlers,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/*
|
|
225
|
+
* Apply one versioned public-form audience change.
|
|
226
|
+
*/
|
|
227
|
+
export function useUpdateCampaignAccess(
|
|
228
|
+
params: UseMutationParams = {},
|
|
229
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
230
|
+
) {
|
|
231
|
+
const { onCompleted, ...rest } = params;
|
|
232
|
+
const [updateCampaignAccess, mtnValues, mtnHandlers, updateObservers] =
|
|
233
|
+
useMutation(updateCampaignAccessMtn, {
|
|
234
|
+
openModalPopUp,
|
|
235
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
236
|
+
onCompleted?.(data?.updateCampaignAccess, error, variables);
|
|
237
|
+
},
|
|
238
|
+
...rest,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
updateCampaignAccess,
|
|
243
|
+
updateObservers,
|
|
244
|
+
...mtnValues,
|
|
245
|
+
...mtnHandlers,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/*
|
|
250
|
+
* Submit or replace one public campaign response and unwrap its acknowledgement payload.
|
|
251
|
+
*/
|
|
252
|
+
export function useSubmitCampaignResponse(
|
|
253
|
+
params: UseMutationParams = {},
|
|
254
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
255
|
+
) {
|
|
256
|
+
const { onCompleted, ...rest } = params;
|
|
257
|
+
const [submitCampaignResponse, mtnValues, mtnHandlers] = useMutation(
|
|
258
|
+
submitCampaignResponseMtn,
|
|
259
|
+
{
|
|
260
|
+
openModalPopUp,
|
|
261
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
262
|
+
onCompleted?.(data?.submitCampaignResponse, error, variables);
|
|
263
|
+
},
|
|
264
|
+
...rest,
|
|
265
|
+
},
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
submitCampaignResponse,
|
|
270
|
+
...mtnValues,
|
|
271
|
+
...mtnHandlers,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/*
|
|
276
|
+
* Create one editable public-form campaign draft.
|
|
277
|
+
*/
|
|
278
|
+
export function useCreateFormCampaignDraft(
|
|
279
|
+
params: UseMutationParams = {},
|
|
280
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
281
|
+
) {
|
|
282
|
+
const { onCompleted, ...rest } = params;
|
|
283
|
+
const [createFormCampaignDraft, mtnValues, mtnHandlers, updateObservers] =
|
|
284
|
+
useMutation(createFormCampaignDraftMtn, {
|
|
285
|
+
openModalPopUp,
|
|
286
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
287
|
+
onCompleted?.(data?.createFormCampaignDraft, error, variables);
|
|
288
|
+
},
|
|
289
|
+
...rest,
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
createFormCampaignDraft,
|
|
294
|
+
updateObservers,
|
|
295
|
+
...mtnValues,
|
|
296
|
+
...mtnHandlers,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/*
|
|
301
|
+
* Create one editable email campaign draft from an active email template.
|
|
302
|
+
*/
|
|
303
|
+
export function useCreateEmailCampaignDraft(
|
|
304
|
+
params: UseMutationParams = {},
|
|
305
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
306
|
+
) {
|
|
307
|
+
const { onCompleted, ...rest } = params;
|
|
308
|
+
const [createEmailCampaignDraft, mtnValues, mtnHandlers, updateObservers] =
|
|
309
|
+
useMutation(createEmailCampaignDraftMtn, {
|
|
310
|
+
openModalPopUp,
|
|
311
|
+
/*
|
|
312
|
+
* Unwrap the created email draft payload for hook consumers.
|
|
313
|
+
*/
|
|
314
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
315
|
+
onCompleted?.(data?.createEmailCampaignDraft, error, variables);
|
|
316
|
+
},
|
|
317
|
+
...rest,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
createEmailCampaignDraft,
|
|
322
|
+
updateObservers,
|
|
323
|
+
...mtnValues,
|
|
324
|
+
...mtnHandlers,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/*
|
|
329
|
+
* Edit one campaign's versioned settings, draft reset, or lifecycle.
|
|
330
|
+
*/
|
|
331
|
+
export function useEditCampaignSettings(
|
|
332
|
+
params: UseMutationParams = {},
|
|
333
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
334
|
+
) {
|
|
335
|
+
const { onCompleted, ...rest } = params;
|
|
336
|
+
const [editCampaignSettings, mtnValues, mtnHandlers, updateObservers] =
|
|
337
|
+
useMutation(editCampaignSettingsMtn, {
|
|
338
|
+
openModalPopUp,
|
|
339
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
340
|
+
onCompleted?.(data?.editCampaignSettings, error, variables);
|
|
341
|
+
},
|
|
342
|
+
...rest,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
editCampaignSettings,
|
|
347
|
+
updateObservers,
|
|
348
|
+
...mtnValues,
|
|
349
|
+
...mtnHandlers,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/*
|
|
354
|
+
* Archive one template. Campaigns published from it keep working.
|
|
355
|
+
*/
|
|
356
|
+
|
|
357
|
+
export function useArchiveCampaignTemplate(
|
|
358
|
+
params: UseMutationParams = {},
|
|
359
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
360
|
+
) {
|
|
361
|
+
const { onCompleted, ...rest } = params;
|
|
362
|
+
|
|
363
|
+
const [archiveCampaignTemplate, mtnValues, mtnHandlers, updateObservers] =
|
|
364
|
+
useMutation(archiveCampaignTemplateMtn, {
|
|
365
|
+
openModalPopUp,
|
|
366
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
367
|
+
onCompleted?.(data?.archiveCampaignTemplate, error, variables);
|
|
368
|
+
},
|
|
369
|
+
...rest,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
return {
|
|
373
|
+
archiveCampaignTemplate,
|
|
374
|
+
updateObservers,
|
|
375
|
+
...mtnValues,
|
|
376
|
+
...mtnHandlers,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/*
|
|
381
|
+
* Send one test of an email campaign's saved content to a member of the
|
|
382
|
+
* organization. It freezes no recipients and uses no send limit.
|
|
383
|
+
*/
|
|
384
|
+
|
|
385
|
+
export function useSendCampaignTestEmail(
|
|
386
|
+
params: UseMutationParams = {},
|
|
387
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
388
|
+
) {
|
|
389
|
+
const { onCompleted, ...rest } = params;
|
|
390
|
+
const [sendCampaignTestEmail, mtnValues, mtnHandlers, updateObservers] =
|
|
391
|
+
useMutation(sendCampaignTestEmailMtn, {
|
|
392
|
+
openModalPopUp,
|
|
393
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
394
|
+
onCompleted?.(data?.sendCampaignTestEmail, error, variables);
|
|
395
|
+
},
|
|
396
|
+
...rest,
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
sendCampaignTestEmail,
|
|
401
|
+
updateObservers,
|
|
402
|
+
...mtnValues,
|
|
403
|
+
...mtnHandlers,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/*
|
|
408
|
+
* @deprecated Create an email campaign draft, select its audience lists, and use
|
|
409
|
+
* useEditCampaignSettings with command.sendEmail.
|
|
410
|
+
*
|
|
411
|
+
* Passing the same idempotency key again returns the original campaign rather than
|
|
412
|
+
* mailing anybody twice, so a retried click is safe.
|
|
413
|
+
*/
|
|
414
|
+
|
|
415
|
+
export function useSendCampaignEmail(
|
|
416
|
+
params: UseMutationParams = {},
|
|
417
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
418
|
+
) {
|
|
419
|
+
const { onCompleted, ...rest } = params;
|
|
420
|
+
|
|
421
|
+
const [sendCampaignEmail, mtnValues, mtnHandlers, updateObservers] =
|
|
422
|
+
useMutation(sendCampaignEmailMtn, {
|
|
423
|
+
openModalPopUp,
|
|
424
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
425
|
+
onCompleted?.(data?.sendCampaignEmail, error, variables);
|
|
426
|
+
},
|
|
427
|
+
...rest,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
return {
|
|
431
|
+
sendCampaignEmail,
|
|
432
|
+
updateObservers,
|
|
433
|
+
...mtnValues,
|
|
434
|
+
...mtnHandlers,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Apply archive-only websocket state without mixing editor revisions or definitions.
|
|
3
|
+
* Tombstones disable existing editors immediately; list membership stays unchanged
|
|
4
|
+
* until the user refreshes. Never resurrect a tombstone from an older query result.
|
|
5
|
+
*/
|
|
6
|
+
export function applyCampaignArchive<
|
|
7
|
+
T extends { id: string; archivedAt?: string | null; __deleted?: boolean },
|
|
8
|
+
>(
|
|
9
|
+
source: T | null | undefined,
|
|
10
|
+
fragment:
|
|
11
|
+
| { id: string; archivedAt?: string | null; __deleted?: boolean }
|
|
12
|
+
| null
|
|
13
|
+
| undefined,
|
|
14
|
+
): T | null | undefined {
|
|
15
|
+
if (!source || source.id !== fragment?.id || !fragment.__deleted)
|
|
16
|
+
return source;
|
|
17
|
+
return {
|
|
18
|
+
...source,
|
|
19
|
+
__deleted: true,
|
|
20
|
+
...(fragment.archivedAt ? { archivedAt: fragment.archivedAt } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/*
|
|
24
|
+
* Keep recipient data scoped to the active campaign, organization, and filters
|
|
25
|
+
* while the shared query client retains an earlier response during navigation.
|
|
26
|
+
*/
|
|
27
|
+
export function getCampaignQueryData<T>(
|
|
28
|
+
result: {
|
|
29
|
+
data?: T | null;
|
|
30
|
+
queryKey: string;
|
|
31
|
+
queryName: string;
|
|
32
|
+
variablesKey: string;
|
|
33
|
+
},
|
|
34
|
+
skipped: boolean,
|
|
35
|
+
): T | null {
|
|
36
|
+
return !skipped &&
|
|
37
|
+
result.queryKey === `#${result.queryName}:${result.variablesKey}`
|
|
38
|
+
? (result.data ?? null)
|
|
39
|
+
: null;
|
|
40
|
+
}
|