@funnelsgrove/runtime 0.11.2 → 0.11.4
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/README.md +51 -0
- package/dist/components/ManageSubscriptionScreen.js +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/services/api.service.d.ts +28 -104
- package/dist/services/api.service.js +24 -519
- package/dist/services/checkout-access.service.d.ts +2 -0
- package/dist/services/checkout-access.service.js +19 -0
- package/dist/services/checkout-identity.service.d.ts +4 -0
- package/dist/services/checkout-identity.service.js +28 -0
- package/dist/services/funnel-sdk/checkout/chargeOneClickPayment.d.ts +2 -0
- package/dist/services/funnel-sdk/checkout/chargeOneClickPayment.js +17 -0
- package/dist/services/funnel-sdk/checkout/createHostedCheckoutSession.d.ts +2 -0
- package/dist/services/funnel-sdk/checkout/createHostedCheckoutSession.js +9 -0
- package/dist/services/funnel-sdk/checkout/createOneTimeCheckout.d.ts +2 -0
- package/dist/services/funnel-sdk/checkout/createOneTimeCheckout.js +21 -0
- package/dist/services/funnel-sdk/checkout/createOneTimePaymentIntent.d.ts +3 -0
- package/dist/services/funnel-sdk/checkout/createOneTimePaymentIntent.js +10 -0
- package/dist/services/funnel-sdk/checkout/createSubscriptionCheckout.d.ts +2 -0
- package/dist/services/funnel-sdk/checkout/createSubscriptionCheckout.js +22 -0
- package/dist/services/funnel-sdk/checkout/requests.d.ts +127 -0
- package/dist/services/funnel-sdk/checkout/requests.js +112 -0
- package/dist/services/{funnel-sdk-payments.functions.d.ts → funnel-sdk/checkout/selection.d.ts} +2 -0
- package/dist/services/{funnel-sdk-payments.functions.js → funnel-sdk/checkout/selection.js} +1 -1
- package/dist/services/funnel-sdk/checkout/types.d.ts +187 -0
- package/dist/services/funnel-sdk/checkout/types.js +1 -0
- package/dist/services/funnel-sdk/checkout/updateSubscriptionCheckoutPlan.d.ts +2 -0
- package/dist/services/funnel-sdk/checkout/updateSubscriptionCheckoutPlan.js +18 -0
- package/dist/services/funnel-sdk/checkout/verifySubscriptionCheckout.d.ts +2 -0
- package/dist/services/funnel-sdk/checkout/verifySubscriptionCheckout.js +25 -0
- package/dist/services/funnel-sdk/shared/http.d.ts +21 -0
- package/dist/services/funnel-sdk/shared/http.js +65 -0
- package/dist/services/funnel-sdk/shared/runtimeConfig.d.ts +17 -0
- package/dist/services/funnel-sdk/shared/runtimeConfig.js +42 -0
- package/dist/services/funnel-sdk/shared/types.d.ts +9 -0
- package/dist/services/funnel-sdk/shared/types.js +1 -0
- package/dist/services/funnel-sdk/subscriptions/listSubscriptions.d.ts +3 -0
- package/dist/services/funnel-sdk/subscriptions/listSubscriptions.js +17 -0
- package/dist/services/funnel-sdk/subscriptions/types.d.ts +24 -0
- package/dist/services/funnel-sdk/subscriptions/types.js +1 -0
- package/dist/services/funnel-sdk/subscriptions/updateSubscription.d.ts +2 -0
- package/dist/services/funnel-sdk/subscriptions/updateSubscription.js +33 -0
- package/dist/services/funnel-sdk/subscriptions/validator.d.ts +2 -0
- package/dist/services/funnel-sdk/subscriptions/validator.js +15 -0
- package/dist/services/funnel-sdk/uploads/preparePhotoUpload.d.ts +4 -0
- package/dist/services/funnel-sdk/uploads/preparePhotoUpload.js +19 -0
- package/dist/services/funnel-sdk/uploads/types.d.ts +32 -0
- package/dist/services/funnel-sdk/uploads/types.js +1 -0
- package/dist/services/funnel-sdk/uploads/uploadPhoto.d.ts +7 -0
- package/dist/services/funnel-sdk/uploads/uploadPhoto.js +18 -0
- package/dist/services/funnel-sdk/uploads/uploadPhotoFile.d.ts +2 -0
- package/dist/services/funnel-sdk/uploads/uploadPhotoFile.js +26 -0
- package/dist/services/funnel-sdk/users/bootstrapUser.d.ts +3 -0
- package/dist/services/funnel-sdk/users/bootstrapUser.js +15 -0
- package/dist/services/funnel-sdk/users/captureEmail.d.ts +2 -0
- package/dist/services/funnel-sdk/users/captureEmail.js +15 -0
- package/dist/services/funnel-sdk/users/claimUserSubscription.d.ts +3 -0
- package/dist/services/funnel-sdk/users/claimUserSubscription.js +7 -0
- package/dist/services/funnel-sdk/users/getCurrentUser.d.ts +3 -0
- package/dist/services/funnel-sdk/users/getCurrentUser.js +13 -0
- package/dist/services/funnel-sdk/users/getUserSubscriptionStatus.d.ts +3 -0
- package/dist/services/funnel-sdk/users/getUserSubscriptionStatus.js +14 -0
- package/dist/services/funnel-sdk/users/types.d.ts +57 -0
- package/dist/services/funnel-sdk/users/types.js +1 -0
- package/dist/services/funnel-sdk/users/updateFunnelUser.d.ts +3 -0
- package/dist/services/funnel-sdk/users/updateFunnelUser.js +18 -0
- package/dist/services/funnel-sdk.service.d.ts +26 -319
- package/dist/services/funnel-sdk.service.js +38 -456
- package/dist/services/session/bootstrap/bootstrapSession.d.ts +8 -0
- package/dist/services/session/bootstrap/bootstrapSession.js +25 -0
- package/dist/services/session/bootstrap/currentUser.d.ts +1 -0
- package/dist/services/session/bootstrap/currentUser.js +37 -0
- package/dist/services/session/bootstrap/idempotency.d.ts +9 -0
- package/dist/services/session/bootstrap/idempotency.js +97 -0
- package/dist/services/session/bootstrap/requests.d.ts +23 -0
- package/dist/services/session/bootstrap/requests.js +25 -0
- package/dist/services/session/bootstrap/responses.d.ts +3 -0
- package/dist/services/session/bootstrap/responses.js +10 -0
- package/dist/services/session/bootstrap/types.d.ts +12 -0
- package/dist/services/session/bootstrap/types.js +1 -0
- package/dist/services/session/emailCapture/captureEmail.d.ts +8 -0
- package/dist/services/session/emailCapture/captureEmail.js +13 -0
- package/dist/services/session/emailCapture/requests.d.ts +12 -0
- package/dist/services/session/emailCapture/requests.js +6 -0
- package/dist/services/session/emailCapture/responses.d.ts +3 -0
- package/dist/services/session/emailCapture/responses.js +14 -0
- package/dist/services/session/emailCapture/types.d.ts +8 -0
- package/dist/services/session/emailCapture/types.js +1 -0
- package/dist/services/session/emailCapture/validator.d.ts +16 -0
- package/dist/services/session/emailCapture/validator.js +37 -0
- package/dist/services/session/identity.d.ts +6 -0
- package/dist/services/session/identity.js +48 -0
- package/dist/services/session/ping/pingUserContext.d.ts +2 -0
- package/dist/services/session/ping/pingUserContext.js +10 -0
- package/dist/services/session/ping/transport.d.ts +2 -0
- package/dist/services/session/ping/transport.js +41 -0
- package/dist/services/session/shared/values.d.ts +6 -0
- package/dist/services/session/shared/values.js +25 -0
- package/dist/services/session/subscriptions/getManageSubscriptions.d.ts +3 -0
- package/dist/services/session/subscriptions/getManageSubscriptions.js +8 -0
- package/dist/services/session/subscriptions/identity.d.ts +3 -0
- package/dist/services/session/subscriptions/identity.js +8 -0
- package/dist/services/session/subscriptions/types.d.ts +35 -0
- package/dist/services/session/subscriptions/types.js +1 -0
- package/dist/services/session/subscriptions/updateSubscription.d.ts +10 -0
- package/dist/services/session/subscriptions/updateSubscription.js +7 -0
- package/dist/services/session/subscriptions/validator.d.ts +6 -0
- package/dist/services/session/subscriptions/validator.js +13 -0
- package/dist/services/session/uploads/localPhoto.d.ts +2 -0
- package/dist/services/session/uploads/localPhoto.js +10 -0
- package/dist/services/session/uploads/requests.d.ts +10 -0
- package/dist/services/session/uploads/requests.js +7 -0
- package/dist/services/session/uploads/types.d.ts +7 -0
- package/dist/services/session/uploads/types.js +1 -0
- package/dist/services/session/uploads/uploadTempPhoto.d.ts +6 -0
- package/dist/services/session/uploads/uploadTempPhoto.js +13 -0
- package/dist/services/session/uploads/validator.d.ts +3 -0
- package/dist/services/session/uploads/validator.js +12 -0
- package/dist/services/session/users/mappers.d.ts +13 -0
- package/dist/services/session/users/mappers.js +33 -0
- package/dist/services/session/users/requests.d.ts +15 -0
- package/dist/services/session/users/requests.js +8 -0
- package/dist/services/session/users/syncUrlUserAttributes.d.ts +10 -0
- package/dist/services/session/users/syncUrlUserAttributes.js +21 -0
- package/dist/services/session/users/types.d.ts +20 -0
- package/dist/services/session/users/types.js +1 -0
- package/dist/services/session/users/updateUser.d.ts +6 -0
- package/dist/services/session/users/updateUser.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FUNNEL_ID, getFunnelSdkPublishableKey } from '../../runtime-api.config.js';
|
|
2
|
+
import { funnelSdkService } from '../../funnel-sdk.service.js';
|
|
3
|
+
import { getOrCreateClientUserId, persistUserId } from '../identity.js';
|
|
4
|
+
import { toPhotoUploadRequest } from './requests.js';
|
|
5
|
+
import { parsePhotoUploadResponse } from './validator.js';
|
|
6
|
+
import { createLocalPhoto } from './localPhoto.js';
|
|
7
|
+
export async function uploadTempPhoto(input) {
|
|
8
|
+
const userId = persistUserId(input.userId || getOrCreateClientUserId(), FUNNEL_ID);
|
|
9
|
+
if (!getFunnelSdkPublishableKey())
|
|
10
|
+
return createLocalPhoto(userId, input.file);
|
|
11
|
+
const payload = await funnelSdkService.uploadPhotoFile(toPhotoUploadRequest(userId, input));
|
|
12
|
+
return parsePhotoUploadResponse(payload, input.file);
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { asString, asNumber } from '../shared/values.js';
|
|
2
|
+
export const parsePhotoUploadResponse = (payload, file) => {
|
|
3
|
+
const publicUrl = asString(payload.publicUrl);
|
|
4
|
+
const key = asString(payload.key);
|
|
5
|
+
const contentType = asString(payload.contentType) || file.type || 'image/jpeg';
|
|
6
|
+
const sizeBytes = asNumber(payload.sizeBytes) || file.size || 0;
|
|
7
|
+
const uploadedAt = asString(payload.uploadedAt) || new Date().toISOString();
|
|
8
|
+
if (!publicUrl || !key) {
|
|
9
|
+
throw new Error('Invalid photo upload response');
|
|
10
|
+
}
|
|
11
|
+
return { key, publicUrl, contentType, sizeBytes, uploadedAt };
|
|
12
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FunnelUserAnswers } from '../../../sdk/userAnswers.js';
|
|
2
|
+
import { type FunnelUserAttribution } from '../../../runtime/funnel-attribution.js';
|
|
3
|
+
import type { AppUser, SdkApiUser } from './types.js';
|
|
4
|
+
export declare const withMergedAttributionDocument: (document: Record<string, unknown> | null | undefined, attribution: FunnelUserAttribution | null | undefined) => Record<string, unknown>;
|
|
5
|
+
export declare const toAppUser: (input: {
|
|
6
|
+
apiUser?: SdkApiUser;
|
|
7
|
+
userId: string;
|
|
8
|
+
fallbackName?: string;
|
|
9
|
+
fallbackEmail?: string;
|
|
10
|
+
fallbackAttributes?: FunnelUserAnswers;
|
|
11
|
+
fallbackDocument?: Record<string, unknown>;
|
|
12
|
+
}) => AppUser;
|
|
13
|
+
export declare const toUpdatedUser: (user: AppUser, userId: string, attribution?: FunnelUserAttribution, apiUser?: SdkApiUser) => AppUser;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mergeFunnelUserAttribution } from '../../../runtime/funnel-attribution.js';
|
|
2
|
+
import { asRecord, asString } from '../shared/values.js';
|
|
3
|
+
export const withMergedAttributionDocument = (document, attribution) => {
|
|
4
|
+
const normalizedDocument = asRecord(document);
|
|
5
|
+
if (!attribution) {
|
|
6
|
+
return normalizedDocument;
|
|
7
|
+
}
|
|
8
|
+
return Object.assign(Object.assign({}, normalizedDocument), { attribution: mergeFunnelUserAttribution(normalizedDocument.attribution, attribution) });
|
|
9
|
+
};
|
|
10
|
+
export const toAppUser = (input) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const apiUser = input.apiUser;
|
|
13
|
+
const apiDocument = asRecord(apiUser === null || apiUser === void 0 ? void 0 : apiUser.document);
|
|
14
|
+
const apiProgress = asRecord(apiDocument.progress);
|
|
15
|
+
const apiAttributes = asRecord(apiProgress.attributes);
|
|
16
|
+
return {
|
|
17
|
+
id: input.userId,
|
|
18
|
+
name: asString(apiUser === null || apiUser === void 0 ? void 0 : apiUser.fullName) || input.fallbackName || '',
|
|
19
|
+
email: asString(apiUser === null || apiUser === void 0 ? void 0 : apiUser.email) || input.fallbackEmail || '',
|
|
20
|
+
attributes: Object.keys(apiAttributes).length > 0
|
|
21
|
+
? apiAttributes
|
|
22
|
+
: ((_a = input.fallbackAttributes) !== null && _a !== void 0 ? _a : {}),
|
|
23
|
+
document: Object.keys(apiDocument).length > 0 ? apiDocument : ((_b = input.fallbackDocument) !== null && _b !== void 0 ? _b : {}),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const toUpdatedUser = (user, userId, attribution, apiUser) => toAppUser({
|
|
27
|
+
apiUser,
|
|
28
|
+
userId,
|
|
29
|
+
fallbackName: user.name,
|
|
30
|
+
fallbackEmail: user.email,
|
|
31
|
+
fallbackAttributes: user.attributes,
|
|
32
|
+
fallbackDocument: withMergedAttributionDocument(user.document, attribution),
|
|
33
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FunnelUserAttribution } from '../../../runtime/funnel-attribution.js';
|
|
2
|
+
import type { AppUser } from './types.js';
|
|
3
|
+
export declare const toUserUpdateRequest: (user: AppUser, userId: string, environment: "test" | "live", attribution?: FunnelUserAttribution) => {
|
|
4
|
+
userId: string;
|
|
5
|
+
email: string | undefined;
|
|
6
|
+
fullName: string | undefined;
|
|
7
|
+
progress: {
|
|
8
|
+
attributes: import("../../../index.js").FunnelUserAnswers;
|
|
9
|
+
};
|
|
10
|
+
metadata: {
|
|
11
|
+
source: string;
|
|
12
|
+
environment: "test" | "live";
|
|
13
|
+
};
|
|
14
|
+
attribution: FunnelUserAttribution | undefined;
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const toUserUpdateRequest = (user, userId, environment, attribution) => ({
|
|
2
|
+
userId,
|
|
3
|
+
email: user.email || undefined,
|
|
4
|
+
fullName: user.name || undefined,
|
|
5
|
+
progress: { attributes: user.attributes || {} },
|
|
6
|
+
metadata: { source: 'funnel', environment },
|
|
7
|
+
attribution,
|
|
8
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type UrlUserAttributes } from '../../../runtime/url-user-attributes.js';
|
|
2
|
+
import type { FunnelUserAnswers } from '../../../sdk/userAnswers.js';
|
|
3
|
+
import type { FunnelUserAttribution } from '../../../runtime/funnel-attribution.js';
|
|
4
|
+
import type { AppUser, AppUserInput } from './types.js';
|
|
5
|
+
export declare function syncUrlUserAttributes(input: {
|
|
6
|
+
user: AppUserInput;
|
|
7
|
+
attributes?: FunnelUserAnswers;
|
|
8
|
+
urlAttributes?: UrlUserAttributes | null;
|
|
9
|
+
attribution?: FunnelUserAttribution;
|
|
10
|
+
}): Promise<AppUser | null>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { applyUrlUserAttributesToUser, hasUrlUserProfileAttributes } from '../../../runtime/url-user-attributes.js';
|
|
2
|
+
import { updateUser } from './updateUser.js';
|
|
3
|
+
export async function syncUrlUserAttributes(input) {
|
|
4
|
+
var _a;
|
|
5
|
+
if (!hasUrlUserProfileAttributes(input.urlAttributes)) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const nextUser = applyUrlUserAttributesToUser({
|
|
9
|
+
user: input.user,
|
|
10
|
+
attributes: input.attributes,
|
|
11
|
+
urlAttributes: input.urlAttributes,
|
|
12
|
+
});
|
|
13
|
+
const updatedUser = await updateUser(Object.assign(Object.assign({}, nextUser), { document: (_a = nextUser.document) !== null && _a !== void 0 ? _a : {} }), {
|
|
14
|
+
attribution: input.attribution,
|
|
15
|
+
});
|
|
16
|
+
return applyUrlUserAttributesToUser({
|
|
17
|
+
user: updatedUser,
|
|
18
|
+
attributes: nextUser.attributes,
|
|
19
|
+
urlAttributes: input.urlAttributes,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FunnelUserAnswers } from '../../../sdk/userAnswers.js';
|
|
2
|
+
export type AppUser = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
email: string;
|
|
6
|
+
attributes: FunnelUserAnswers;
|
|
7
|
+
document: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
export type AppUserInput = Omit<AppUser, 'document'> & {
|
|
10
|
+
document?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
export type SdkApiUser = {
|
|
13
|
+
user_id?: unknown;
|
|
14
|
+
fullName?: unknown;
|
|
15
|
+
email?: unknown;
|
|
16
|
+
document?: unknown;
|
|
17
|
+
};
|
|
18
|
+
export type UpdateUserResponse = {
|
|
19
|
+
user?: SdkApiUser;
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FunnelUserAttribution } from '../../../runtime/funnel-attribution.js';
|
|
2
|
+
import type { AppUser } from './types.js';
|
|
3
|
+
export declare function updateUser(user: AppUser, options?: {
|
|
4
|
+
attribution?: FunnelUserAttribution;
|
|
5
|
+
persistClientIdentity?: boolean;
|
|
6
|
+
}): Promise<AppUser>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FUNNEL_ID, getFunnelSdkPublishableKey } from '../../runtime-api.config.js';
|
|
2
|
+
import { funnelSdkService } from '../../funnel-sdk.service.js';
|
|
3
|
+
import { getRuntimeMode } from '../../runtime-mode.service.js';
|
|
4
|
+
import { normalizeUserId } from '../shared/values.js';
|
|
5
|
+
import { getOrCreateClientUserId, persistUserId } from '../identity.js';
|
|
6
|
+
import { toUpdatedUser } from './mappers.js';
|
|
7
|
+
import { toUserUpdateRequest } from './requests.js';
|
|
8
|
+
export async function updateUser(user, options) {
|
|
9
|
+
const userId = normalizeUserId(user.id) || getOrCreateClientUserId();
|
|
10
|
+
const persistedUserId = (options === null || options === void 0 ? void 0 : options.persistClientIdentity) === false
|
|
11
|
+
? userId
|
|
12
|
+
: persistUserId(userId, FUNNEL_ID);
|
|
13
|
+
if (!getFunnelSdkPublishableKey()) {
|
|
14
|
+
return toUpdatedUser(user, persistedUserId, options === null || options === void 0 ? void 0 : options.attribution);
|
|
15
|
+
}
|
|
16
|
+
const payload = await funnelSdkService.updateFunnelUser(toUserUpdateRequest(user, persistedUserId, getRuntimeMode(), options === null || options === void 0 ? void 0 : options.attribution));
|
|
17
|
+
return toUpdatedUser(user, persistedUserId, options === null || options === void 0 ? void 0 : options.attribution, payload.user);
|
|
18
|
+
}
|