@forgeroute/ui 0.4.38 → 0.4.40

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.
@@ -1,9 +1,11 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, Injectable, InjectionToken, PLATFORM_ID, ViewEncapsulation, computed, effect, inject, input, output, signal, untracked, viewChild } from "@angular/core";
3
3
  import { DOCUMENT, isPlatformBrowser } from "@angular/common";
4
- import { AlertComponent, BadgeComponent, ButtonComponent, FormRowComponent, FormSectionComponent, ModalComponent, SkeletonComponent, TextComponent, TextInputComponent } from "@forgeroute/ui";
4
+ import { AlertComponent, BadgeComponent, ButtonComponent, FORGEROUTE_CONFIG, FormRowComponent, FormSectionComponent, ModalComponent, OptionCardComponent, SkeletonComponent, TextComponent, TextInputComponent } from "@forgeroute/ui";
5
5
  import * as i1 from "@angular/forms";
6
6
  import { FormsModule } from "@angular/forms";
7
+ import { HttpClient, HttpErrorResponse, HttpParams } from "@angular/common/http";
8
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
7
9
  const sdkImporter = { load: () => import("@stripe/stripe-js") };
8
10
  const defaultStripeLoader = async (publishableKey, options) => {
9
11
  const sdk = await sdkImporter.load();
@@ -2822,6 +2824,406 @@ i0.ɵɵngDeclareClassMetadata({
2822
2824
  }]
2823
2825
  }
2824
2826
  });
2825
- export { MICRODEPOSIT_COPY, MicrodepositVerifyComponent, STRIPE_A11Y_MESSAGES, STRIPE_ACH_NOTICE, STRIPE_DEFAULT_ERROR_MESSAGE, STRIPE_ERROR_MESSAGES, STRIPE_LOADER, STRIPE_PAYMENT_DEFAULTS, STRIPE_TECHNICAL_ERROR_MESSAGES, StripePaymentComponent, StripePaymentService, buildLoadOptions, defaultStripeLoader, depositAmountError, descriptorCodeError, getStripeErrorMessage, isDarkPage, microdepositArrivalText, microdepositCancelMessage, microdepositKeepsActiveText, microdepositProcessingText, microdepositStepsText, normalizeDescriptorCode, normalizeIntent, outcomeOf, paymentMethodIdOf, provideStripePayment, readStripeAppearance, readStripeReturnParams, retrieveIntent, verificationOf, verifyMicrodeposits };
2827
+ var StripeConnectComponent = class StripeConnectComponent {
2828
+ constructor() {
2829
+ this.http = inject(HttpClient);
2830
+ this.destroyRef = inject(DestroyRef);
2831
+ this.apiBase = inject(FORGEROUTE_CONFIG, { optional: true })?.baseUrl ?? "/api";
2832
+ this.statusEndpoint = input("/integrations/stripe/status", ...ngDevMode ? [{ debugName: "statusEndpoint" }] : /* istanbul ignore next */ []);
2833
+ this.connectEndpoint = input("/integrations/stripe/connect", ...ngDevMode ? [{ debugName: "connectEndpoint" }] : /* istanbul ignore next */ []);
2834
+ this.connectParams = input(null, ...ngDevMode ? [{ debugName: "connectParams" }] : /* istanbul ignore next */ []);
2835
+ this.title = input("Stripe", ...ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []);
2836
+ this.description = input("Collect your customers' payments online. You finish setting up your account on Stripe, then come back here. Payouts go straight to your Stripe account.", ...ngDevMode ? [{ debugName: "description" }] : /* istanbul ignore next */ []);
2837
+ this.connectedText = input("Connected. Payments go straight to your Stripe account.", ...ngDevMode ? [{ debugName: "connectedText" }] : /* istanbul ignore next */ []);
2838
+ this.connectLabel = input("Connect", ...ngDevMode ? [{ debugName: "connectLabel" }] : /* istanbul ignore next */ []);
2839
+ this.reconnectLabel = input("Reconnect", ...ngDevMode ? [{ debugName: "reconnectLabel" }] : /* istanbul ignore next */ []);
2840
+ this.loadFailedText = input("The Stripe connection could not be loaded. Please try again.", ...ngDevMode ? [{ debugName: "loadFailedText" }] : /* istanbul ignore next */ []);
2841
+ this.connectFailedText = input("Stripe could not be reached. Please try again.", ...ngDevMode ? [{ debugName: "connectFailedText" }] : /* istanbul ignore next */ []);
2842
+ this.disabled = input(false, ...ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []);
2843
+ this.statusChange = output();
2844
+ this.connected = signal(false, ...ngDevMode ? [{ debugName: "connected" }] : /* istanbul ignore next */ []);
2845
+ this.statusKnown = signal(false, ...ngDevMode ? [{ debugName: "statusKnown" }] : /* istanbul ignore next */ []);
2846
+ this.connecting = signal(false, ...ngDevMode ? [{ debugName: "connecting" }] : /* istanbul ignore next */ []);
2847
+ this.error = signal("", ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
2848
+ this.busy = computed(() => !this.statusKnown() && !this.error() || this.connecting(), ...ngDevMode ? [{ debugName: "busy" }] : /* istanbul ignore next */ []);
2849
+ this.started = false;
2850
+ effect(() => {
2851
+ this.statusEndpoint();
2852
+ untracked(() => {
2853
+ if (!this.started) {
2854
+ this.started = true;
2855
+ this.refresh();
2856
+ }
2857
+ });
2858
+ });
2859
+ }
2860
+ refresh() {
2861
+ this.error.set("");
2862
+ this.http.get(this.apiBase + this.statusEndpoint()).pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
2863
+ next: (body) => {
2864
+ const connected = body?.connected === true;
2865
+ this.connected.set(connected);
2866
+ this.statusKnown.set(true);
2867
+ this.statusChange.emit(connected);
2868
+ },
2869
+ error: (e) => {
2870
+ this.statusKnown.set(false);
2871
+ this.error.set(this.messageOf(e, this.loadFailedText()));
2872
+ }
2873
+ });
2874
+ }
2875
+ connect() {
2876
+ if (this.connecting() || this.disabled()) return;
2877
+ this.error.set("");
2878
+ this.connecting.set(true);
2879
+ let params = new HttpParams();
2880
+ for (const [k, v] of Object.entries(this.connectParams() ?? {})) params = params.set(k, v);
2881
+ this.http.get(this.apiBase + this.connectEndpoint(), { params }).pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
2882
+ next: (res) => {
2883
+ const url = res?.url ?? res?.authUrl ?? res?.onboardingUrl;
2884
+ if (!url || !this.isWebAddress(url)) {
2885
+ this.connecting.set(false);
2886
+ this.error.set(this.connectFailedText());
2887
+ return;
2888
+ }
2889
+ this.redirect(url);
2890
+ },
2891
+ error: (e) => {
2892
+ this.connecting.set(false);
2893
+ this.error.set(this.messageOf(e, this.connectFailedText()));
2894
+ }
2895
+ });
2896
+ }
2897
+ redirect(url) {
2898
+ window.location.href = url;
2899
+ }
2900
+ isWebAddress(url) {
2901
+ try {
2902
+ const p = new URL(url, window.location.origin).protocol;
2903
+ return p === "https:" || p === "http:";
2904
+ } catch {
2905
+ return false;
2906
+ }
2907
+ }
2908
+ messageOf(e, fallback) {
2909
+ const text = (e instanceof HttpErrorResponse ? e.error : null)?.message;
2910
+ return typeof text === "string" && text ? text : fallback;
2911
+ }
2912
+ static {
2913
+ this.ɵfac = i0.ɵɵngDeclareFactory({
2914
+ minVersion: "12.0.0",
2915
+ version: "22.2.2",
2916
+ ngImport: i0,
2917
+ type: StripeConnectComponent,
2918
+ deps: [],
2919
+ target: i0.ɵɵFactoryTarget.Component
2920
+ });
2921
+ }
2922
+ static {
2923
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
2924
+ minVersion: "17.0.0",
2925
+ version: "22.2.2",
2926
+ type: StripeConnectComponent,
2927
+ isStandalone: true,
2928
+ selector: "ui-stripe-connect",
2929
+ inputs: {
2930
+ statusEndpoint: {
2931
+ classPropertyName: "statusEndpoint",
2932
+ publicName: "statusEndpoint",
2933
+ isSignal: true,
2934
+ isRequired: false,
2935
+ transformFunction: null
2936
+ },
2937
+ connectEndpoint: {
2938
+ classPropertyName: "connectEndpoint",
2939
+ publicName: "connectEndpoint",
2940
+ isSignal: true,
2941
+ isRequired: false,
2942
+ transformFunction: null
2943
+ },
2944
+ connectParams: {
2945
+ classPropertyName: "connectParams",
2946
+ publicName: "connectParams",
2947
+ isSignal: true,
2948
+ isRequired: false,
2949
+ transformFunction: null
2950
+ },
2951
+ title: {
2952
+ classPropertyName: "title",
2953
+ publicName: "title",
2954
+ isSignal: true,
2955
+ isRequired: false,
2956
+ transformFunction: null
2957
+ },
2958
+ description: {
2959
+ classPropertyName: "description",
2960
+ publicName: "description",
2961
+ isSignal: true,
2962
+ isRequired: false,
2963
+ transformFunction: null
2964
+ },
2965
+ connectedText: {
2966
+ classPropertyName: "connectedText",
2967
+ publicName: "connectedText",
2968
+ isSignal: true,
2969
+ isRequired: false,
2970
+ transformFunction: null
2971
+ },
2972
+ connectLabel: {
2973
+ classPropertyName: "connectLabel",
2974
+ publicName: "connectLabel",
2975
+ isSignal: true,
2976
+ isRequired: false,
2977
+ transformFunction: null
2978
+ },
2979
+ reconnectLabel: {
2980
+ classPropertyName: "reconnectLabel",
2981
+ publicName: "reconnectLabel",
2982
+ isSignal: true,
2983
+ isRequired: false,
2984
+ transformFunction: null
2985
+ },
2986
+ loadFailedText: {
2987
+ classPropertyName: "loadFailedText",
2988
+ publicName: "loadFailedText",
2989
+ isSignal: true,
2990
+ isRequired: false,
2991
+ transformFunction: null
2992
+ },
2993
+ connectFailedText: {
2994
+ classPropertyName: "connectFailedText",
2995
+ publicName: "connectFailedText",
2996
+ isSignal: true,
2997
+ isRequired: false,
2998
+ transformFunction: null
2999
+ },
3000
+ disabled: {
3001
+ classPropertyName: "disabled",
3002
+ publicName: "disabled",
3003
+ isSignal: true,
3004
+ isRequired: false,
3005
+ transformFunction: null
3006
+ }
3007
+ },
3008
+ outputs: { statusChange: "statusChange" },
3009
+ ngImport: i0,
3010
+ template: `
3011
+ <div class="sc" data-testid="stripe-connect" [attr.aria-busy]="busy() ? 'true' : null">
3012
+ <ui-option-card [title]="title()" letter="S" color="#635bff" [description]="connected() ? connectedText() : description()"
3013
+ [actionLabel]="statusKnown() ? (connected() ? reconnectLabel() : connectLabel()) : ''" [actionVariant]="connected() ? 'secondary' : 'primary'"
3014
+ [actionAriaLabel]="(connected() ? reconnectLabel() : connectLabel()) + ' ' + title()" actionTestId="stripe-connect-action"
3015
+ [actionLoading]="connecting()" [disabled]="disabled() || connecting()" (action)="connect()" />
3016
+ @if (error(); as message) {
3017
+ <ui-alert class="sc-error" variant="danger" data-testid="stripe-connect-error">{{ message }}</ui-alert>
3018
+ @if (!statusKnown()) {
3019
+ <ui-button class="sc-retry" variant="secondary" size="sm" data-testid="stripe-connect-retry" (click)="refresh()">Try again</ui-button>
3020
+ }
3021
+ }
3022
+ </div>
3023
+ `,
3024
+ isInline: true,
3025
+ styles: ["ui-stripe-connect{display:block;min-width:0}ui-stripe-connect .sc-error{display:block;margin-top:12px}ui-stripe-connect .sc-retry{display:inline-block;margin-top:12px}\n"],
3026
+ dependencies: [
3027
+ {
3028
+ kind: "component",
3029
+ type: OptionCardComponent,
3030
+ selector: "ui-option-card",
3031
+ inputs: [
3032
+ "title",
3033
+ "description",
3034
+ "letter",
3035
+ "icon",
3036
+ "color",
3037
+ "actionLabel",
3038
+ "actionVariant",
3039
+ "actionAriaLabel",
3040
+ "actionTestId",
3041
+ "actionLoading",
3042
+ "disabled"
3043
+ ],
3044
+ outputs: ["action"]
3045
+ },
3046
+ {
3047
+ kind: "component",
3048
+ type: AlertComponent,
3049
+ selector: "ui-alert",
3050
+ inputs: [
3051
+ "variant",
3052
+ "title",
3053
+ "dismissible",
3054
+ "dismissAriaLabel",
3055
+ "quiet",
3056
+ "compact",
3057
+ "inline"
3058
+ ],
3059
+ outputs: ["dismissed"]
3060
+ },
3061
+ {
3062
+ kind: "component",
3063
+ type: ButtonComponent,
3064
+ selector: "ui-button",
3065
+ inputs: [
3066
+ "variant",
3067
+ "routerLink",
3068
+ "queryParams",
3069
+ "fragment",
3070
+ "state",
3071
+ "href",
3072
+ "target",
3073
+ "rel",
3074
+ "shortLabel",
3075
+ "shortBelow",
3076
+ "color",
3077
+ "active",
3078
+ "size",
3079
+ "type",
3080
+ "disabled",
3081
+ "loading",
3082
+ "fullWidth",
3083
+ "ariaLabel",
3084
+ "ariaExpanded",
3085
+ "ariaPressed",
3086
+ "ariaDescribedBy",
3087
+ "modal-footer-left",
3088
+ "modal-footer-right"
3089
+ ]
3090
+ }
3091
+ ],
3092
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
3093
+ encapsulation: i0.ViewEncapsulation.None
3094
+ });
3095
+ }
3096
+ };
3097
+ i0.ɵɵngDeclareClassMetadata({
3098
+ minVersion: "12.0.0",
3099
+ version: "22.2.2",
3100
+ ngImport: i0,
3101
+ type: StripeConnectComponent,
3102
+ decorators: [{
3103
+ type: Component,
3104
+ args: [{
3105
+ selector: "ui-stripe-connect",
3106
+ standalone: true,
3107
+ changeDetection: ChangeDetectionStrategy.OnPush,
3108
+ imports: [
3109
+ OptionCardComponent,
3110
+ AlertComponent,
3111
+ ButtonComponent
3112
+ ],
3113
+ template: `
3114
+ <div class="sc" data-testid="stripe-connect" [attr.aria-busy]="busy() ? 'true' : null">
3115
+ <ui-option-card [title]="title()" letter="S" color="#635bff" [description]="connected() ? connectedText() : description()"
3116
+ [actionLabel]="statusKnown() ? (connected() ? reconnectLabel() : connectLabel()) : ''" [actionVariant]="connected() ? 'secondary' : 'primary'"
3117
+ [actionAriaLabel]="(connected() ? reconnectLabel() : connectLabel()) + ' ' + title()" actionTestId="stripe-connect-action"
3118
+ [actionLoading]="connecting()" [disabled]="disabled() || connecting()" (action)="connect()" />
3119
+ @if (error(); as message) {
3120
+ <ui-alert class="sc-error" variant="danger" data-testid="stripe-connect-error">{{ message }}</ui-alert>
3121
+ @if (!statusKnown()) {
3122
+ <ui-button class="sc-retry" variant="secondary" size="sm" data-testid="stripe-connect-retry" (click)="refresh()">Try again</ui-button>
3123
+ }
3124
+ }
3125
+ </div>
3126
+ `,
3127
+ encapsulation: ViewEncapsulation.None,
3128
+ styles: ["ui-stripe-connect{display:block;min-width:0}ui-stripe-connect .sc-error{display:block;margin-top:12px}ui-stripe-connect .sc-retry{display:inline-block;margin-top:12px}\n"]
3129
+ }]
3130
+ }],
3131
+ ctorParameters: () => [],
3132
+ propDecorators: {
3133
+ statusEndpoint: [{
3134
+ type: i0.Input,
3135
+ args: [{
3136
+ isSignal: true,
3137
+ alias: "statusEndpoint",
3138
+ required: false
3139
+ }]
3140
+ }],
3141
+ connectEndpoint: [{
3142
+ type: i0.Input,
3143
+ args: [{
3144
+ isSignal: true,
3145
+ alias: "connectEndpoint",
3146
+ required: false
3147
+ }]
3148
+ }],
3149
+ connectParams: [{
3150
+ type: i0.Input,
3151
+ args: [{
3152
+ isSignal: true,
3153
+ alias: "connectParams",
3154
+ required: false
3155
+ }]
3156
+ }],
3157
+ title: [{
3158
+ type: i0.Input,
3159
+ args: [{
3160
+ isSignal: true,
3161
+ alias: "title",
3162
+ required: false
3163
+ }]
3164
+ }],
3165
+ description: [{
3166
+ type: i0.Input,
3167
+ args: [{
3168
+ isSignal: true,
3169
+ alias: "description",
3170
+ required: false
3171
+ }]
3172
+ }],
3173
+ connectedText: [{
3174
+ type: i0.Input,
3175
+ args: [{
3176
+ isSignal: true,
3177
+ alias: "connectedText",
3178
+ required: false
3179
+ }]
3180
+ }],
3181
+ connectLabel: [{
3182
+ type: i0.Input,
3183
+ args: [{
3184
+ isSignal: true,
3185
+ alias: "connectLabel",
3186
+ required: false
3187
+ }]
3188
+ }],
3189
+ reconnectLabel: [{
3190
+ type: i0.Input,
3191
+ args: [{
3192
+ isSignal: true,
3193
+ alias: "reconnectLabel",
3194
+ required: false
3195
+ }]
3196
+ }],
3197
+ loadFailedText: [{
3198
+ type: i0.Input,
3199
+ args: [{
3200
+ isSignal: true,
3201
+ alias: "loadFailedText",
3202
+ required: false
3203
+ }]
3204
+ }],
3205
+ connectFailedText: [{
3206
+ type: i0.Input,
3207
+ args: [{
3208
+ isSignal: true,
3209
+ alias: "connectFailedText",
3210
+ required: false
3211
+ }]
3212
+ }],
3213
+ disabled: [{
3214
+ type: i0.Input,
3215
+ args: [{
3216
+ isSignal: true,
3217
+ alias: "disabled",
3218
+ required: false
3219
+ }]
3220
+ }],
3221
+ statusChange: [{
3222
+ type: i0.Output,
3223
+ args: ["statusChange"]
3224
+ }]
3225
+ }
3226
+ });
3227
+ export { MICRODEPOSIT_COPY, MicrodepositVerifyComponent, STRIPE_A11Y_MESSAGES, STRIPE_ACH_NOTICE, STRIPE_DEFAULT_ERROR_MESSAGE, STRIPE_ERROR_MESSAGES, STRIPE_LOADER, STRIPE_PAYMENT_DEFAULTS, STRIPE_TECHNICAL_ERROR_MESSAGES, StripeConnectComponent, StripePaymentComponent, StripePaymentService, buildLoadOptions, defaultStripeLoader, depositAmountError, descriptorCodeError, getStripeErrorMessage, isDarkPage, microdepositArrivalText, microdepositCancelMessage, microdepositKeepsActiveText, microdepositProcessingText, microdepositStepsText, normalizeDescriptorCode, normalizeIntent, outcomeOf, paymentMethodIdOf, provideStripePayment, readStripeAppearance, readStripeReturnParams, retrieveIntent, verificationOf, verifyMicrodeposits };
2826
3228
 
2827
3229
  //# sourceMappingURL=forgeroute-ui-stripe.mjs.map