@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.
Files changed (129) hide show
  1. package/README.md +51 -0
  2. package/dist/components/ManageSubscriptionScreen.js +7 -2
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/services/api.service.d.ts +28 -104
  6. package/dist/services/api.service.js +24 -519
  7. package/dist/services/checkout-access.service.d.ts +2 -0
  8. package/dist/services/checkout-access.service.js +19 -0
  9. package/dist/services/checkout-identity.service.d.ts +4 -0
  10. package/dist/services/checkout-identity.service.js +28 -0
  11. package/dist/services/funnel-sdk/checkout/chargeOneClickPayment.d.ts +2 -0
  12. package/dist/services/funnel-sdk/checkout/chargeOneClickPayment.js +17 -0
  13. package/dist/services/funnel-sdk/checkout/createHostedCheckoutSession.d.ts +2 -0
  14. package/dist/services/funnel-sdk/checkout/createHostedCheckoutSession.js +9 -0
  15. package/dist/services/funnel-sdk/checkout/createOneTimeCheckout.d.ts +2 -0
  16. package/dist/services/funnel-sdk/checkout/createOneTimeCheckout.js +21 -0
  17. package/dist/services/funnel-sdk/checkout/createOneTimePaymentIntent.d.ts +3 -0
  18. package/dist/services/funnel-sdk/checkout/createOneTimePaymentIntent.js +10 -0
  19. package/dist/services/funnel-sdk/checkout/createSubscriptionCheckout.d.ts +2 -0
  20. package/dist/services/funnel-sdk/checkout/createSubscriptionCheckout.js +22 -0
  21. package/dist/services/funnel-sdk/checkout/requests.d.ts +127 -0
  22. package/dist/services/funnel-sdk/checkout/requests.js +112 -0
  23. package/dist/services/{funnel-sdk-payments.functions.d.ts → funnel-sdk/checkout/selection.d.ts} +2 -0
  24. package/dist/services/{funnel-sdk-payments.functions.js → funnel-sdk/checkout/selection.js} +1 -1
  25. package/dist/services/funnel-sdk/checkout/types.d.ts +187 -0
  26. package/dist/services/funnel-sdk/checkout/types.js +1 -0
  27. package/dist/services/funnel-sdk/checkout/updateSubscriptionCheckoutPlan.d.ts +2 -0
  28. package/dist/services/funnel-sdk/checkout/updateSubscriptionCheckoutPlan.js +18 -0
  29. package/dist/services/funnel-sdk/checkout/verifySubscriptionCheckout.d.ts +2 -0
  30. package/dist/services/funnel-sdk/checkout/verifySubscriptionCheckout.js +25 -0
  31. package/dist/services/funnel-sdk/shared/http.d.ts +21 -0
  32. package/dist/services/funnel-sdk/shared/http.js +65 -0
  33. package/dist/services/funnel-sdk/shared/runtimeConfig.d.ts +17 -0
  34. package/dist/services/funnel-sdk/shared/runtimeConfig.js +42 -0
  35. package/dist/services/funnel-sdk/shared/types.d.ts +9 -0
  36. package/dist/services/funnel-sdk/shared/types.js +1 -0
  37. package/dist/services/funnel-sdk/subscriptions/listSubscriptions.d.ts +3 -0
  38. package/dist/services/funnel-sdk/subscriptions/listSubscriptions.js +17 -0
  39. package/dist/services/funnel-sdk/subscriptions/types.d.ts +24 -0
  40. package/dist/services/funnel-sdk/subscriptions/types.js +1 -0
  41. package/dist/services/funnel-sdk/subscriptions/updateSubscription.d.ts +2 -0
  42. package/dist/services/funnel-sdk/subscriptions/updateSubscription.js +33 -0
  43. package/dist/services/funnel-sdk/subscriptions/validator.d.ts +2 -0
  44. package/dist/services/funnel-sdk/subscriptions/validator.js +15 -0
  45. package/dist/services/funnel-sdk/uploads/preparePhotoUpload.d.ts +4 -0
  46. package/dist/services/funnel-sdk/uploads/preparePhotoUpload.js +19 -0
  47. package/dist/services/funnel-sdk/uploads/types.d.ts +32 -0
  48. package/dist/services/funnel-sdk/uploads/types.js +1 -0
  49. package/dist/services/funnel-sdk/uploads/uploadPhoto.d.ts +7 -0
  50. package/dist/services/funnel-sdk/uploads/uploadPhoto.js +18 -0
  51. package/dist/services/funnel-sdk/uploads/uploadPhotoFile.d.ts +2 -0
  52. package/dist/services/funnel-sdk/uploads/uploadPhotoFile.js +26 -0
  53. package/dist/services/funnel-sdk/users/bootstrapUser.d.ts +3 -0
  54. package/dist/services/funnel-sdk/users/bootstrapUser.js +15 -0
  55. package/dist/services/funnel-sdk/users/captureEmail.d.ts +2 -0
  56. package/dist/services/funnel-sdk/users/captureEmail.js +15 -0
  57. package/dist/services/funnel-sdk/users/claimUserSubscription.d.ts +3 -0
  58. package/dist/services/funnel-sdk/users/claimUserSubscription.js +7 -0
  59. package/dist/services/funnel-sdk/users/getCurrentUser.d.ts +3 -0
  60. package/dist/services/funnel-sdk/users/getCurrentUser.js +13 -0
  61. package/dist/services/funnel-sdk/users/getUserSubscriptionStatus.d.ts +3 -0
  62. package/dist/services/funnel-sdk/users/getUserSubscriptionStatus.js +14 -0
  63. package/dist/services/funnel-sdk/users/types.d.ts +57 -0
  64. package/dist/services/funnel-sdk/users/types.js +1 -0
  65. package/dist/services/funnel-sdk/users/updateFunnelUser.d.ts +3 -0
  66. package/dist/services/funnel-sdk/users/updateFunnelUser.js +18 -0
  67. package/dist/services/funnel-sdk.service.d.ts +26 -319
  68. package/dist/services/funnel-sdk.service.js +38 -456
  69. package/dist/services/session/bootstrap/bootstrapSession.d.ts +8 -0
  70. package/dist/services/session/bootstrap/bootstrapSession.js +25 -0
  71. package/dist/services/session/bootstrap/currentUser.d.ts +1 -0
  72. package/dist/services/session/bootstrap/currentUser.js +37 -0
  73. package/dist/services/session/bootstrap/idempotency.d.ts +9 -0
  74. package/dist/services/session/bootstrap/idempotency.js +97 -0
  75. package/dist/services/session/bootstrap/requests.d.ts +23 -0
  76. package/dist/services/session/bootstrap/requests.js +25 -0
  77. package/dist/services/session/bootstrap/responses.d.ts +3 -0
  78. package/dist/services/session/bootstrap/responses.js +10 -0
  79. package/dist/services/session/bootstrap/types.d.ts +12 -0
  80. package/dist/services/session/bootstrap/types.js +1 -0
  81. package/dist/services/session/emailCapture/captureEmail.d.ts +8 -0
  82. package/dist/services/session/emailCapture/captureEmail.js +13 -0
  83. package/dist/services/session/emailCapture/requests.d.ts +12 -0
  84. package/dist/services/session/emailCapture/requests.js +6 -0
  85. package/dist/services/session/emailCapture/responses.d.ts +3 -0
  86. package/dist/services/session/emailCapture/responses.js +14 -0
  87. package/dist/services/session/emailCapture/types.d.ts +8 -0
  88. package/dist/services/session/emailCapture/types.js +1 -0
  89. package/dist/services/session/emailCapture/validator.d.ts +16 -0
  90. package/dist/services/session/emailCapture/validator.js +37 -0
  91. package/dist/services/session/identity.d.ts +6 -0
  92. package/dist/services/session/identity.js +48 -0
  93. package/dist/services/session/ping/pingUserContext.d.ts +2 -0
  94. package/dist/services/session/ping/pingUserContext.js +10 -0
  95. package/dist/services/session/ping/transport.d.ts +2 -0
  96. package/dist/services/session/ping/transport.js +41 -0
  97. package/dist/services/session/shared/values.d.ts +6 -0
  98. package/dist/services/session/shared/values.js +25 -0
  99. package/dist/services/session/subscriptions/getManageSubscriptions.d.ts +3 -0
  100. package/dist/services/session/subscriptions/getManageSubscriptions.js +8 -0
  101. package/dist/services/session/subscriptions/identity.d.ts +3 -0
  102. package/dist/services/session/subscriptions/identity.js +8 -0
  103. package/dist/services/session/subscriptions/types.d.ts +35 -0
  104. package/dist/services/session/subscriptions/types.js +1 -0
  105. package/dist/services/session/subscriptions/updateSubscription.d.ts +10 -0
  106. package/dist/services/session/subscriptions/updateSubscription.js +7 -0
  107. package/dist/services/session/subscriptions/validator.d.ts +6 -0
  108. package/dist/services/session/subscriptions/validator.js +13 -0
  109. package/dist/services/session/uploads/localPhoto.d.ts +2 -0
  110. package/dist/services/session/uploads/localPhoto.js +10 -0
  111. package/dist/services/session/uploads/requests.d.ts +10 -0
  112. package/dist/services/session/uploads/requests.js +7 -0
  113. package/dist/services/session/uploads/types.d.ts +7 -0
  114. package/dist/services/session/uploads/types.js +1 -0
  115. package/dist/services/session/uploads/uploadTempPhoto.d.ts +6 -0
  116. package/dist/services/session/uploads/uploadTempPhoto.js +13 -0
  117. package/dist/services/session/uploads/validator.d.ts +3 -0
  118. package/dist/services/session/uploads/validator.js +12 -0
  119. package/dist/services/session/users/mappers.d.ts +13 -0
  120. package/dist/services/session/users/mappers.js +33 -0
  121. package/dist/services/session/users/requests.d.ts +15 -0
  122. package/dist/services/session/users/requests.js +8 -0
  123. package/dist/services/session/users/syncUrlUserAttributes.d.ts +10 -0
  124. package/dist/services/session/users/syncUrlUserAttributes.js +21 -0
  125. package/dist/services/session/users/types.d.ts +20 -0
  126. package/dist/services/session/users/types.js +1 -0
  127. package/dist/services/session/users/updateUser.d.ts +6 -0
  128. package/dist/services/session/users/updateUser.js +18 -0
  129. package/package.json +1 -1
@@ -0,0 +1,42 @@
1
+ import { buildMainApiUrl, FUNNEL_ID, FUNNEL_VERSION_ID, FUNNEL_SDK_PUBLISHABLE_KEY, } from '../../runtime-api.config.js';
2
+ import { resolvePreviewPaymentPublishableKey } from '../../public-env.js';
3
+ const trimTrailingSlash = (value) => value.replace(/\/+$/, '');
4
+ const toNormalizedPath = (path) => (path.startsWith('/') ? path : `/${path}`);
5
+ export const asTrimmedStringOrNull = (value) => {
6
+ if (typeof value !== 'string') {
7
+ return null;
8
+ }
9
+ const trimmed = value.trim();
10
+ return trimmed || null;
11
+ };
12
+ export const removeEmptyFields = (input) => {
13
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined && value !== null && value !== ''));
14
+ };
15
+ export const resolveRuntimeConfig = (runtimeConfig) => {
16
+ var _a, _b, _c;
17
+ return ({
18
+ apiBaseUrl: asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.apiBaseUrl),
19
+ funnelId: (_a = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelId)) !== null && _a !== void 0 ? _a : asTrimmedStringOrNull(FUNNEL_ID),
20
+ funnelVersionId: (_b = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelVersionId)) !== null && _b !== void 0 ? _b : asTrimmedStringOrNull(FUNNEL_VERSION_ID),
21
+ funnelSdkPublishableKey: resolvePreviewPaymentPublishableKey((_c = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelSdkPublishableKey)) !== null && _c !== void 0 ? _c : asTrimmedStringOrNull(FUNNEL_SDK_PUBLISHABLE_KEY)) || null,
22
+ paymentsApiVersion: (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.paymentsApiVersion) === 'v2' ? 'v2' : 'v1',
23
+ });
24
+ };
25
+ export const buildApiUrl = (path, runtimeConfig) => {
26
+ const { apiBaseUrl } = resolveRuntimeConfig(runtimeConfig);
27
+ if (!apiBaseUrl) {
28
+ return buildMainApiUrl(path);
29
+ }
30
+ return `${trimTrailingSlash(apiBaseUrl)}${toNormalizedPath(path)}`;
31
+ };
32
+ export const buildHeaders = (runtimeConfig, headers) => {
33
+ const { funnelSdkPublishableKey } = resolveRuntimeConfig(runtimeConfig);
34
+ if (!funnelSdkPublishableKey) {
35
+ return Object.assign({}, (headers !== null && headers !== void 0 ? headers : {}));
36
+ }
37
+ return Object.assign({ 'x-sdk-publishable-key': funnelSdkPublishableKey }, (headers !== null && headers !== void 0 ? headers : {}));
38
+ };
39
+ export const withRuntimeFields = (runtimeConfig, body, options) => {
40
+ const { funnelId, funnelVersionId, funnelSdkPublishableKey } = resolveRuntimeConfig(runtimeConfig);
41
+ return removeEmptyFields(Object.assign({ publishableKey: (options === null || options === void 0 ? void 0 : options.includePublishableKey) === false ? undefined : funnelSdkPublishableKey || undefined, funnelId: funnelId || undefined, funnelVersionId: funnelVersionId || undefined }, (body !== null && body !== void 0 ? body : {})));
42
+ };
@@ -0,0 +1,9 @@
1
+ export type FunnelSdkRuntimeMode = 'test' | 'live';
2
+ export type FunnelSdkRuntimeConfigOverrides = {
3
+ apiBaseUrl?: string | null;
4
+ funnelId?: string | null;
5
+ funnelVersionId?: string | null;
6
+ funnelSdkPublishableKey?: string | null;
7
+ paymentsApiVersion?: 'v1' | 'v2' | null;
8
+ };
9
+ export type FunnelSdkJsonObject = Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { FunnelSdkListSubscriptionsInput } from './types.js';
2
+ import type { FunnelSdkJsonObject } from '../shared/types.js';
3
+ export declare const listSubscriptions: <ResponsePayload = FunnelSdkJsonObject>(input?: FunnelSdkListSubscriptionsInput) => Promise<ResponsePayload>;
@@ -0,0 +1,17 @@
1
+ import { getJson } from '../shared/http.js';
2
+ import { resolveRuntimeConfig } from '../shared/runtimeConfig.js';
3
+ export const listSubscriptions = async (input = {}) => {
4
+ var _a;
5
+ const { funnelId, paymentsApiVersion } = resolveRuntimeConfig(input.runtimeConfig);
6
+ return getJson(paymentsApiVersion === 'v2'
7
+ ? '/sdk/public/v2/subscriptions'
8
+ : '/sdk/public/subscriptions', {
9
+ runtimeConfig: input.runtimeConfig,
10
+ searchParams: {
11
+ user_id: input.userId,
12
+ stripe_customer_id: input.stripeCustomerId,
13
+ funnelId: (_a = input.funnelId) !== null && _a !== void 0 ? _a : funnelId,
14
+ },
15
+ errorMessage: 'Failed to load subscriptions',
16
+ });
17
+ };
@@ -0,0 +1,24 @@
1
+ import type { FunnelSdkRuntimeConfigOverrides } from '../shared/types.js';
2
+ export type FunnelSdkSubscriptionRef = {
3
+ provider: 'stripe' | 'solidgate';
4
+ paymentProfileId: string;
5
+ providerSubscriptionId: string;
6
+ environment: 'test' | 'live';
7
+ };
8
+ export type FunnelSdkUpdateSubscriptionInput = {
9
+ subscriptionId: string;
10
+ subscriptionRef?: FunnelSdkSubscriptionRef | null;
11
+ action: 'cancel' | 'renew' | 'apply-discount';
12
+ couponId?: string | null;
13
+ cancellationMode?: 'period_end' | 'immediate';
14
+ funnelId?: string | null;
15
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
16
+ stripeCustomerId?: string | null;
17
+ userId?: string | null;
18
+ };
19
+ export type FunnelSdkListSubscriptionsInput = {
20
+ funnelId?: string | null;
21
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
22
+ stripeCustomerId?: string | null;
23
+ userId?: string | null;
24
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { FunnelSdkUpdateSubscriptionInput } from './types.js';
2
+ export declare const updateSubscription: <ResponsePayload>(input: FunnelSdkUpdateSubscriptionInput) => Promise<ResponsePayload>;
@@ -0,0 +1,33 @@
1
+ import { postJson } from '../shared/http.js';
2
+ import { resolveRuntimeConfig } from '../shared/runtimeConfig.js';
3
+ import { requireSubscriptionRef } from './validator.js';
4
+ export const updateSubscription = async (input) => {
5
+ if (resolveRuntimeConfig(input.runtimeConfig).paymentsApiVersion === 'v2') {
6
+ return postJson(`/sdk/public/v2/subscriptions/${input.action}`, {
7
+ runtimeConfig: input.runtimeConfig,
8
+ body: {
9
+ userId: input.userId,
10
+ stripeCustomerId: input.stripeCustomerId,
11
+ funnelId: input.funnelId,
12
+ subscriptionRef: requireSubscriptionRef(input.subscriptionRef),
13
+ cancellationMode: input.cancellationMode,
14
+ couponId: input.couponId,
15
+ },
16
+ includeRuntimeFields: false,
17
+ includePublishableKey: false,
18
+ errorMessage: 'Failed to update subscription',
19
+ });
20
+ }
21
+ return postJson(`/sdk/public/subscriptions/${encodeURIComponent(input.subscriptionId)}/${input.action}`, {
22
+ runtimeConfig: input.runtimeConfig,
23
+ body: {
24
+ user_id: input.userId,
25
+ stripe_customer_id: input.stripeCustomerId,
26
+ funnelId: input.funnelId,
27
+ coupon_id: input.couponId,
28
+ },
29
+ includeRuntimeFields: false,
30
+ includePublishableKey: false,
31
+ errorMessage: 'Failed to update subscription',
32
+ });
33
+ };
@@ -0,0 +1,2 @@
1
+ import type { FunnelSdkSubscriptionRef } from './types.js';
2
+ export declare const requireSubscriptionRef: (value: FunnelSdkSubscriptionRef | null | undefined) => FunnelSdkSubscriptionRef;
@@ -0,0 +1,15 @@
1
+ export const requireSubscriptionRef = (value) => {
2
+ if (!value ||
3
+ (value.provider !== 'stripe' && value.provider !== 'solidgate') ||
4
+ !value.paymentProfileId.trim() ||
5
+ !value.providerSubscriptionId.trim() ||
6
+ (value.environment !== 'test' && value.environment !== 'live')) {
7
+ throw new Error('V2 subscription reference is required');
8
+ }
9
+ return {
10
+ provider: value.provider,
11
+ paymentProfileId: value.paymentProfileId.trim(),
12
+ providerSubscriptionId: value.providerSubscriptionId.trim(),
13
+ environment: value.environment,
14
+ };
15
+ };
@@ -0,0 +1,4 @@
1
+ import type { FunnelSdkUploadPhotoFileInput, FunnelSdkPreparedPhotoUpload } from './types.js';
2
+ export declare const preparePhotoUpload: (input: Omit<FunnelSdkUploadPhotoFileInput, "file"> & {
3
+ sizeBytes: number;
4
+ }) => Promise<FunnelSdkPreparedPhotoUpload>;
@@ -0,0 +1,19 @@
1
+ import { postJson } from '../shared/http.js';
2
+ import { resolveRuntimeConfig } from '../shared/runtimeConfig.js';
3
+ export const preparePhotoUpload = async (input) => {
4
+ const { funnelId } = resolveRuntimeConfig(input.runtimeConfig);
5
+ return postJson('/sdk/public/uploads/photos/prepare', {
6
+ runtimeConfig: input.runtimeConfig,
7
+ body: {
8
+ funnelId,
9
+ userId: input.userId,
10
+ fileName: input.fileName,
11
+ contentType: input.contentType,
12
+ sizeBytes: input.sizeBytes,
13
+ source: input.source,
14
+ },
15
+ includeRuntimeFields: false,
16
+ includePublishableKey: false,
17
+ errorMessage: 'Failed to prepare photo upload',
18
+ });
19
+ };
@@ -0,0 +1,32 @@
1
+ import type { FunnelSdkRuntimeConfigOverrides } from '../shared/types.js';
2
+ /**
3
+ * @deprecated Compatibility contract for already-published funnel bundles.
4
+ * New runtime code must use FunnelSdkUploadPhotoFileInput and uploadPhotoFile.
5
+ */
6
+ export type FunnelSdkUploadPhotoInput = {
7
+ fileName: string;
8
+ imageDataUrl: string;
9
+ mimeType?: string | null;
10
+ source?: 'camera' | 'upload' | string | null;
11
+ userId?: string | null;
12
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
13
+ };
14
+ export type FunnelSdkUploadPhotoFileInput = {
15
+ file: Blob;
16
+ fileName: string;
17
+ contentType?: string | null;
18
+ source?: 'camera' | 'upload' | string | null;
19
+ userId?: string | null;
20
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
21
+ };
22
+ export type FunnelSdkPreparedPhotoUpload = {
23
+ key: string;
24
+ publicUrl: string;
25
+ uploadUrl: string;
26
+ uploadHeaders: Record<string, string>;
27
+ contentType: string;
28
+ sizeBytes: number;
29
+ };
30
+ export type FunnelSdkUploadedPhoto = Omit<FunnelSdkPreparedPhotoUpload, 'uploadUrl' | 'uploadHeaders'> & {
31
+ uploadedAt: string;
32
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { FunnelSdkUploadPhotoInput } from './types.js';
2
+ import type { FunnelSdkJsonObject } from '../shared/types.js';
3
+ /**
4
+ * @deprecated Compatibility transport for already-published funnel bundles.
5
+ * New runtime code must use uploadPhotoFile so image bytes go directly to R2.
6
+ */
7
+ export declare const uploadPhoto: <ResponsePayload = FunnelSdkJsonObject>(input: FunnelSdkUploadPhotoInput) => Promise<ResponsePayload>;
@@ -0,0 +1,18 @@
1
+ import { postJson } from '../shared/http.js';
2
+ /**
3
+ * @deprecated Compatibility transport for already-published funnel bundles.
4
+ * New runtime code must use uploadPhotoFile so image bytes go directly to R2.
5
+ */
6
+ export const uploadPhoto = async (input) => {
7
+ return postJson('/sdk/public/uploads/photos', {
8
+ runtimeConfig: input.runtimeConfig,
9
+ body: {
10
+ user_id: input.userId,
11
+ fileName: input.fileName,
12
+ mimeType: input.mimeType,
13
+ imageDataUrl: input.imageDataUrl,
14
+ source: input.source,
15
+ },
16
+ errorMessage: 'Failed to upload photo',
17
+ });
18
+ };
@@ -0,0 +1,2 @@
1
+ import type { FunnelSdkUploadPhotoFileInput, FunnelSdkUploadedPhoto } from './types.js';
2
+ export declare const uploadPhotoFile: (input: FunnelSdkUploadPhotoFileInput) => Promise<FunnelSdkUploadedPhoto>;
@@ -0,0 +1,26 @@
1
+ import { preparePhotoUpload } from './preparePhotoUpload.js';
2
+ export const uploadPhotoFile = async (input) => {
3
+ const prepared = await preparePhotoUpload({
4
+ fileName: input.fileName,
5
+ contentType: input.contentType,
6
+ sizeBytes: input.file.size,
7
+ source: input.source,
8
+ userId: input.userId,
9
+ runtimeConfig: input.runtimeConfig,
10
+ });
11
+ const response = await fetch(prepared.uploadUrl, {
12
+ method: 'PUT',
13
+ headers: prepared.uploadHeaders,
14
+ body: input.file,
15
+ });
16
+ if (!response.ok) {
17
+ throw new Error(`Failed to upload photo (${response.status})`);
18
+ }
19
+ return {
20
+ key: prepared.key,
21
+ publicUrl: prepared.publicUrl,
22
+ contentType: prepared.contentType,
23
+ sizeBytes: prepared.sizeBytes,
24
+ uploadedAt: new Date().toISOString(),
25
+ };
26
+ };
@@ -0,0 +1,3 @@
1
+ import type { FunnelSdkBootstrapUserInput } from './types.js';
2
+ import type { FunnelSdkJsonObject } from '../shared/types.js';
3
+ export declare const bootstrapUser: <ResponsePayload = FunnelSdkJsonObject>(input?: FunnelSdkBootstrapUserInput) => Promise<ResponsePayload>;
@@ -0,0 +1,15 @@
1
+ import { postJson } from '../shared/http.js';
2
+ export const bootstrapUser = async (input = {}) => {
3
+ return postJson('/sdk/public/users/bootstrap', {
4
+ runtimeConfig: input.runtimeConfig,
5
+ body: {
6
+ user_id: input.userId,
7
+ idempotencyKey: input.idempotencyKey,
8
+ email: input.email,
9
+ fullName: input.fullName,
10
+ metadata: input.metadata,
11
+ attribution: input.attribution,
12
+ },
13
+ errorMessage: 'Failed to bootstrap user session',
14
+ });
15
+ };
@@ -0,0 +1,2 @@
1
+ import type { FunnelSdkCaptureEmailInput, FunnelSdkCaptureEmailResponse } from './types.js';
2
+ export declare const captureEmail: (input: FunnelSdkCaptureEmailInput) => Promise<FunnelSdkCaptureEmailResponse>;
@@ -0,0 +1,15 @@
1
+ import { postJson } from '../shared/http.js';
2
+ import { CURRENT_STEP_CONTRACT_VERSION } from '../../../steps/step-contract.js';
3
+ export const captureEmail = async (input) => {
4
+ return postJson('/sdk/public/users/email-capture', {
5
+ runtimeConfig: input.runtimeConfig,
6
+ body: {
7
+ user_id: input.userId,
8
+ email: input.email,
9
+ environment: input.environment,
10
+ answers: input.answers,
11
+ stepContractVersion: CURRENT_STEP_CONTRACT_VERSION,
12
+ },
13
+ errorMessage: 'Failed to capture email',
14
+ });
15
+ };
@@ -0,0 +1,3 @@
1
+ import type { FunnelSdkClaimUserSubscriptionInput } from './types.js';
2
+ import type { FunnelSdkJsonObject } from '../shared/types.js';
3
+ export declare const claimUserSubscription: <ResponsePayload = FunnelSdkJsonObject>(input: FunnelSdkClaimUserSubscriptionInput) => Promise<ResponsePayload>;
@@ -0,0 +1,7 @@
1
+ import { postJson } from '../shared/http.js';
2
+ export const claimUserSubscription = async (input) => {
3
+ return postJson(`/sdk/public/users/${encodeURIComponent(input.userId)}/claim_subscription`, {
4
+ runtimeConfig: input.runtimeConfig,
5
+ errorMessage: 'Failed to claim user subscription',
6
+ });
7
+ };
@@ -0,0 +1,3 @@
1
+ import type { FunnelSdkGetCurrentUserInput } from './types.js';
2
+ import type { FunnelSdkJsonObject } from '../shared/types.js';
3
+ export declare const getCurrentUser: <ResponsePayload = FunnelSdkJsonObject>(input: FunnelSdkGetCurrentUserInput) => Promise<ResponsePayload>;
@@ -0,0 +1,13 @@
1
+ import { getJson } from '../shared/http.js';
2
+ import { resolveRuntimeConfig } from '../shared/runtimeConfig.js';
3
+ export const getCurrentUser = async (input) => {
4
+ const { funnelId } = resolveRuntimeConfig(input.runtimeConfig);
5
+ return getJson('/sdk/public/users/me', {
6
+ runtimeConfig: input.runtimeConfig,
7
+ searchParams: {
8
+ funnelId,
9
+ user_id: input.userId,
10
+ },
11
+ errorMessage: 'Failed to load user',
12
+ });
13
+ };
@@ -0,0 +1,3 @@
1
+ import type { FunnelSdkGetUserSubscriptionStatusInput } from './types.js';
2
+ import type { FunnelSdkJsonObject } from '../shared/types.js';
3
+ export declare const getUserSubscriptionStatus: <ResponsePayload = FunnelSdkJsonObject>(input?: FunnelSdkGetUserSubscriptionStatusInput) => Promise<ResponsePayload>;
@@ -0,0 +1,14 @@
1
+ import { getJson } from '../shared/http.js';
2
+ import { resolveRuntimeConfig } from '../shared/runtimeConfig.js';
3
+ export const getUserSubscriptionStatus = async (input = {}) => {
4
+ const { funnelId } = resolveRuntimeConfig(input.runtimeConfig);
5
+ return getJson('/sdk/public/users/subscription', {
6
+ runtimeConfig: input.runtimeConfig,
7
+ searchParams: {
8
+ funnelId,
9
+ user_id: input.userId,
10
+ email: input.email,
11
+ },
12
+ errorMessage: 'Failed to load user subscription status',
13
+ });
14
+ };
@@ -0,0 +1,57 @@
1
+ import type { FunnelSdkRuntimeMode, FunnelSdkRuntimeConfigOverrides, FunnelSdkJsonObject } from '../shared/types.js';
2
+ export type FunnelSdkBootstrapUserInput = {
3
+ userId?: string | null;
4
+ idempotencyKey?: string | null;
5
+ email?: string | null;
6
+ fullName?: string | null;
7
+ metadata?: FunnelSdkJsonObject | null;
8
+ attribution?: FunnelSdkJsonObject | null;
9
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
10
+ };
11
+ export type FunnelSdkCaptureEmailInput = {
12
+ userId: string;
13
+ email: string;
14
+ environment: FunnelSdkRuntimeMode;
15
+ answers?: FunnelSdkJsonObject;
16
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
17
+ };
18
+ export type FunnelSdkCaptureEmailResponse = {
19
+ user: {
20
+ user_id?: unknown;
21
+ fullName?: unknown;
22
+ email?: unknown;
23
+ document?: unknown;
24
+ };
25
+ canonicalUser?: {
26
+ user_id?: unknown;
27
+ email?: unknown;
28
+ } | null;
29
+ activeSubscription: boolean;
30
+ eventId: string;
31
+ eventCreated: boolean;
32
+ };
33
+ export type FunnelSdkGetCurrentUserInput = {
34
+ userId: string;
35
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
36
+ };
37
+ export type FunnelSdkGetUserSubscriptionStatusInput = {
38
+ userId?: string | null;
39
+ email?: string | null;
40
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
41
+ };
42
+ export type FunnelSdkClaimUserSubscriptionInput = {
43
+ userId: string;
44
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
45
+ };
46
+ export type FunnelSdkUpdateFunnelUserInput = {
47
+ userId: string;
48
+ email?: string | null;
49
+ fullName?: string | null;
50
+ document?: FunnelSdkJsonObject | null;
51
+ progress?: FunnelSdkJsonObject | null;
52
+ metadata?: FunnelSdkJsonObject | null;
53
+ attribution?: FunnelSdkJsonObject | null;
54
+ subscription?: FunnelSdkJsonObject | null;
55
+ subscriptionStatus?: string | null;
56
+ runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
57
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { FunnelSdkUpdateFunnelUserInput } from './types.js';
2
+ import type { FunnelSdkJsonObject } from '../shared/types.js';
3
+ export declare const updateFunnelUser: <ResponsePayload = FunnelSdkJsonObject>(input: FunnelSdkUpdateFunnelUserInput) => Promise<ResponsePayload>;
@@ -0,0 +1,18 @@
1
+ import { postJson } from '../shared/http.js';
2
+ export const updateFunnelUser = async (input) => {
3
+ return postJson('/public/funnel-users/upsert', {
4
+ runtimeConfig: input.runtimeConfig,
5
+ body: {
6
+ user_id: input.userId,
7
+ email: input.email,
8
+ fullName: input.fullName,
9
+ document: input.document,
10
+ progress: input.progress,
11
+ metadata: input.metadata,
12
+ attribution: input.attribution,
13
+ subscription: input.subscription,
14
+ subscriptionStatus: input.subscriptionStatus,
15
+ },
16
+ errorMessage: 'Failed to update user',
17
+ });
18
+ };