@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,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,3 @@
1
+ import type { FunnelSdkUploadedPhoto } from '../../funnel-sdk.service.js';
2
+ import type { TempPhotoUploadResult } from './types.js';
3
+ export declare const parsePhotoUploadResponse: (payload: FunnelSdkUploadedPhoto, file: File) => TempPhotoUploadResult;
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",