@primer-io/primer-js 0.1.9 → 0.2.0

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.
@@ -198,6 +198,24 @@ export interface PropertyDeclaration<Type = unknown, TypeHint = unknown> {
198
198
  * the property changes.
199
199
  */
200
200
  readonly noAccessor?: boolean;
201
+ /**
202
+ * When `true`, uses the initial value of the property as the default value,
203
+ * which changes how attributes are handled:
204
+ * - The initial value does *not* reflect, even if the `reflect` option is `true`.
205
+ * Subsequent changes to the property will reflect, even if they are equal to the
206
+ * default value.
207
+ * - When the attribute is removed, the property is set to the default value
208
+ * - The initial value will not trigger an old value in the `changedProperties` map
209
+ * argument to update lifecycle methods.
210
+ *
211
+ * When set, properties must be initialized, either with a field initializer, or an
212
+ * assignment in the constructor. Not initializing the property may lead to
213
+ * improper handling of subsequent property assignments.
214
+ *
215
+ * While this behavior is opt-in, most properties that reflect to attributes should
216
+ * use `useDefault: true` so that their initial values do not reflect.
217
+ */
218
+ useDefault?: boolean;
201
219
  }
202
220
  /**
203
221
  * Map of properties to PropertyDeclaration options. For each property an
@@ -556,6 +574,11 @@ declare abstract class ReactiveElement extends HTMLElement implements ReactiveCo
556
574
  * @category updates
557
575
  */
558
576
  hasUpdated: boolean;
577
+ /**
578
+ * Records property default values when the
579
+ * `useDefault` option is used.
580
+ */
581
+ private __defaultValues?;
559
582
  /**
560
583
  * Properties that should be reflected when updated.
561
584
  */
@@ -593,13 +616,7 @@ declare abstract class ReactiveElement extends HTMLElement implements ReactiveCo
593
616
  * Fixes any properties set on the instance before upgrade time.
594
617
  * Otherwise these would shadow the accessor and break these properties.
595
618
  * The properties are stored in a Map which is played back after the
596
- * constructor runs. Note, on very old versions of Safari (<=9) or Chrome
597
- * (<=41), properties created for native platform properties like (`id` or
598
- * `name`) may not have default values set in the element constructor. On
599
- * these browsers native properties appear on instances and therefore their
600
- * default value will overwrite any element default (e.g. if the element sets
601
- * this.id = 'id' in the constructor, the 'id' will become '' since this is
602
- * the native platform default).
619
+ * constructor runs.
603
620
  */
604
621
  private __saveInstanceProperties;
605
622
  /**
@@ -640,7 +657,7 @@ declare abstract class ReactiveElement extends HTMLElement implements ReactiveCo
640
657
  * overridden, `super.attributeChangedCallback(name, _old, value)` must be
641
658
  * called.
642
659
  *
643
- * See [using the lifecycle callbacks](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#using_the_lifecycle_callbacks)
660
+ * See [responding to attribute changes](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes)
644
661
  * on MDN for more information about the `attributeChangedCallback`.
645
662
  * @category attributes
646
663
  */
@@ -2393,12 +2410,65 @@ export declare class InitializedPayments {
2393
2410
  toArray(): InitializedPaymentMethod[];
2394
2411
  size(): number;
2395
2412
  }
2396
- export interface OnCheckoutCompletePayload {
2413
+ export interface PaymentData {
2414
+ paymentMethodType: string;
2415
+ }
2416
+ export interface PrepareHandler {
2417
+ continuePaymentCreation: () => void;
2418
+ abortPaymentCreation: () => void;
2419
+ }
2420
+ export interface PaymentCompleteData {
2397
2421
  payment: Payment | null;
2422
+ status: "success" | "pending" | "error";
2423
+ error?: PrimerClientError;
2398
2424
  }
2399
- export interface OnCheckoutFailurePayload {
2400
- error: PrimerClientError;
2401
- payment?: Payment;
2425
+ /**
2426
+ * PrimerJS is a wrapper class that provides a stable API for interfacing with the Primer SDK
2427
+ * while hiding direct access to the legacy headless instance.
2428
+ */
2429
+ export declare class PrimerJS {
2430
+ private headlessInstance;
2431
+ private paymentMethods;
2432
+ onPaymentStart?: () => void;
2433
+ onPaymentPrepare?: (data: PaymentData, handler: PrepareHandler) => void;
2434
+ onPaymentComplete?: (data: PaymentCompleteData) => void;
2435
+ constructor(headlessInstance: PrimerHeadlessCheckout);
2436
+ /**
2437
+ * Set the initialized payment methods
2438
+ * @internal - This is only used internally by the SDK
2439
+ */
2440
+ setPaymentMethods(methods: InitializedPayments): void;
2441
+ /**
2442
+ * Refetches a new client session from merchant backend.
2443
+ */
2444
+ refreshSession(): Promise<void>;
2445
+ /**
2446
+ * Returns the cached list of payment methods.
2447
+ */
2448
+ getPaymentMethods(): PaymentMethodInfo[];
2449
+ /**
2450
+ * Internal method to handle the onPaymentStart callback
2451
+ * @internal - This is only used internally by the SDK
2452
+ */
2453
+ handlePaymentStart(): void;
2454
+ /**
2455
+ * Internal method to handle the onBeforePaymentCreate callback and transform it to onPaymentPrepare
2456
+ * @internal - This is only used internally by the SDK
2457
+ */
2458
+ handleBeforePaymentCreate(data: PaymentData, originalHandler: {
2459
+ continuePaymentCreation: () => void;
2460
+ abortPaymentCreation: () => void;
2461
+ }): void;
2462
+ /**
2463
+ * Internal method to handle payment completion (success)
2464
+ * @internal - This is only used internally by the SDK
2465
+ */
2466
+ handlePaymentComplete(payment: Payment | null): void;
2467
+ /**
2468
+ * Internal method to handle payment failure
2469
+ * @internal - This is only used internally by the SDK
2470
+ */
2471
+ handlePaymentFailure(error: PrimerClientError, payment?: Payment): void;
2402
2472
  }
2403
2473
  export interface CardSubmitSuccessPayload {
2404
2474
  result: unknown;
@@ -2410,14 +2480,12 @@ export interface PrimeAchErrorPayload {
2410
2480
  error: Error;
2411
2481
  }
2412
2482
  export interface PrimerEvents {
2413
- "primer-state-changed": CustomEvent<SdkStateContext>;
2414
- "primer-oncheckout-complete": CustomEvent<OnCheckoutCompletePayload>;
2415
- "primer-oncheckout-failure": CustomEvent<OnCheckoutFailurePayload>;
2416
- "primer-payment-methods-updated": CustomEvent<InitializedPayments>;
2417
- "primer-checkout-initialized": CustomEvent<PrimerHeadlessCheckout>;
2418
- "primer-card-network-change": CustomEvent<CardNetworksContext>;
2419
- "primer-card-submit-success": CustomEvent<CardSubmitSuccessPayload>;
2420
- "primer-card-submit-errors": CustomEvent<CardSubmitErrorsPayload>;
2483
+ "primer:state-change": CustomEvent<SdkStateContext>;
2484
+ "primer:methods-update": CustomEvent<InitializedPayments>;
2485
+ "primer:ready": CustomEvent<PrimerJS>;
2486
+ "primer:card-network-change": CustomEvent<CardNetworksContext>;
2487
+ "primer:card-success": CustomEvent<CardSubmitSuccessPayload>;
2488
+ "primer:card-error": CustomEvent<CardSubmitErrorsPayload>;
2421
2489
  "primer-ach-error": CustomEvent<PrimeAchErrorPayload>;
2422
2490
  "primer-ach-bank-details-collected": CustomEvent;
2423
2491
  "primer-ach-mandate-confirmed": CustomEvent;
@@ -2437,10 +2505,8 @@ declare class PrimerEventsController implements ReactiveController {
2437
2505
  dispatchEvent<K extends keyof PrimerEvents>(type: K, detail: PrimerEvents[K]["detail"]): void;
2438
2506
  dispatchSdkState(sdkState: SdkStateContext): void;
2439
2507
  dispatchPaymentMethods(paymentMethods: InitializedPayments): void;
2440
- dispatchCheckoutInitialized(checkoutInstance: PrimerHeadlessCheckout): void;
2508
+ dispatchCheckoutInitialized(checkoutInstance: PrimerJS): void;
2441
2509
  dispatchCardNetworkChange(network: CardNetworksContext): void;
2442
- dispatchOnCheckoutComplete(payment: Payment | null): void;
2443
- dispatchOnCheckoutFailure(error: PrimerClientError, payment?: Payment): void;
2444
2510
  dispatchFormSubmitSuccess(result: unknown): void;
2445
2511
  dispatchFormSubmitErrors(errors: unknown): void;
2446
2512
  }
@@ -2733,6 +2799,146 @@ declare class StyleProcessingController implements ReactiveController {
2733
2799
  */
2734
2800
  hostDisconnected(): void;
2735
2801
  }
2802
+ interface ReactiveControllerHost$1 {
2803
+ /**
2804
+ * Adds a controller to the host, which sets up the controller's lifecycle
2805
+ * methods to be called with the host's lifecycle.
2806
+ */
2807
+ addController(controller: ReactiveController$1): void;
2808
+ /**
2809
+ * Removes a controller from the host.
2810
+ */
2811
+ removeController(controller: ReactiveController$1): void;
2812
+ /**
2813
+ * Requests a host update which is processed asynchronously. The update can
2814
+ * be waited on via the `updateComplete` property.
2815
+ */
2816
+ requestUpdate(): void;
2817
+ /**
2818
+ * Returns a Promise that resolves when the host has completed updating.
2819
+ * The Promise value is a boolean that is `true` if the element completed the
2820
+ * update without triggering another update. The Promise result is `false` if
2821
+ * a property was set inside `updated()`. If the Promise is rejected, an
2822
+ * exception was thrown during the update.
2823
+ *
2824
+ * @return A promise of a boolean that indicates if the update resolved
2825
+ * without triggering another update.
2826
+ */
2827
+ readonly updateComplete: Promise<boolean>;
2828
+ }
2829
+ interface ReactiveController$1 {
2830
+ /**
2831
+ * Called when the host is connected to the component tree. For custom
2832
+ * element hosts, this corresponds to the `connectedCallback()` lifecycle,
2833
+ * which is only called when the component is connected to the document.
2834
+ */
2835
+ hostConnected?(): void;
2836
+ /**
2837
+ * Called when the host is disconnected from the component tree. For custom
2838
+ * element hosts, this corresponds to the `disconnectedCallback()` lifecycle,
2839
+ * which is called the host or an ancestor component is disconnected from the
2840
+ * document.
2841
+ */
2842
+ hostDisconnected?(): void;
2843
+ /**
2844
+ * Called during the client-side host update, just before the host calls
2845
+ * its own update.
2846
+ *
2847
+ * Code in `update()` can depend on the DOM as it is not called in
2848
+ * server-side rendering.
2849
+ */
2850
+ hostUpdate?(): void;
2851
+ /**
2852
+ * Called after a host update, just before the host calls firstUpdated and
2853
+ * updated. It is not called in server-side rendering.
2854
+ *
2855
+ */
2856
+ hostUpdated?(): void;
2857
+ }
2858
+ interface ComplexAttributeConverter$1<Type = unknown, TypeHint = unknown> {
2859
+ /**
2860
+ * Called to convert an attribute value to a property
2861
+ * value.
2862
+ */
2863
+ fromAttribute?(value: string | null, type?: TypeHint): Type;
2864
+ /**
2865
+ * Called to convert a property value to an attribute
2866
+ * value.
2867
+ *
2868
+ * It returns unknown instead of string, to be compatible with
2869
+ * https://github.com/WICG/trusted-types (and similar efforts).
2870
+ */
2871
+ toAttribute?(value: Type, type?: TypeHint): unknown;
2872
+ }
2873
+ type AttributeConverter$1<Type = unknown, TypeHint = unknown> = ComplexAttributeConverter$1<Type> | ((value: string | null, type?: TypeHint) => Type);
2874
+ interface PropertyDeclaration$1<Type = unknown, TypeHint = unknown> {
2875
+ /**
2876
+ * When set to `true`, indicates the property is internal private state. The
2877
+ * property should not be set by users. When using TypeScript, this property
2878
+ * should be marked as `private` or `protected`, and it is also a common
2879
+ * practice to use a leading `_` in the name. The property is not added to
2880
+ * `observedAttributes`.
2881
+ */
2882
+ readonly state?: boolean;
2883
+ /**
2884
+ * Indicates how and whether the property becomes an observed attribute.
2885
+ * If the value is `false`, the property is not added to `observedAttributes`.
2886
+ * If true or absent, the lowercased property name is observed (e.g. `fooBar`
2887
+ * becomes `foobar`). If a string, the string value is observed (e.g
2888
+ * `attribute: 'foo-bar'`).
2889
+ */
2890
+ readonly attribute?: boolean | string;
2891
+ /**
2892
+ * Indicates the type of the property. This is used only as a hint for the
2893
+ * `converter` to determine how to convert the attribute
2894
+ * to/from a property.
2895
+ */
2896
+ readonly type?: TypeHint;
2897
+ /**
2898
+ * Indicates how to convert the attribute to/from a property. If this value
2899
+ * is a function, it is used to convert the attribute value a the property
2900
+ * value. If it's an object, it can have keys for `fromAttribute` and
2901
+ * `toAttribute`. If no `toAttribute` function is provided and
2902
+ * `reflect` is set to `true`, the property value is set directly to the
2903
+ * attribute. A default `converter` is used if none is provided; it supports
2904
+ * `Boolean`, `String`, `Number`, `Object`, and `Array`. Note,
2905
+ * when a property changes and the converter is used to update the attribute,
2906
+ * the property is never updated again as a result of the attribute changing,
2907
+ * and vice versa.
2908
+ */
2909
+ readonly converter?: AttributeConverter$1<Type, TypeHint>;
2910
+ /**
2911
+ * Indicates if the property should reflect to an attribute.
2912
+ * If `true`, when the property is set, the attribute is set using the
2913
+ * attribute name determined according to the rules for the `attribute`
2914
+ * property option and the value of the property converted using the rules
2915
+ * from the `converter` property option.
2916
+ */
2917
+ readonly reflect?: boolean;
2918
+ /**
2919
+ * A function that indicates if a property should be considered changed when
2920
+ * it is set. The function should take the `newValue` and `oldValue` and
2921
+ * return `true` if an update should be requested.
2922
+ */
2923
+ hasChanged?(value: Type, oldValue: Type): boolean;
2924
+ /**
2925
+ * Indicates whether an accessor will be created for this property. By
2926
+ * default, an accessor will be generated for this property that requests an
2927
+ * update when set. If this flag is `true`, no accessor will be created, and
2928
+ * it will be the user's responsibility to call
2929
+ * `this.requestUpdate(propertyName, oldValue)` to request an update when
2930
+ * the property changes.
2931
+ */
2932
+ readonly noAccessor?: boolean;
2933
+ }
2934
+ declare global {
2935
+ interface SymbolConstructor {
2936
+ readonly metadata: unique symbol;
2937
+ }
2938
+ }
2939
+ declare global {
2940
+ var litPropertyMetadata: WeakMap<object, Map<PropertyKey, PropertyDeclaration$1>>;
2941
+ }
2736
2942
  declare const sourceLocale = `en`;
2737
2943
  declare const targetLocales = [
2738
2944
  `ar`,
@@ -3942,6 +4148,62 @@ export interface HostedInputHost extends ReactiveControllerHost, LitElement {
3942
4148
  label: string;
3943
4149
  requestUpdate: ReactiveControllerHost["requestUpdate"];
3944
4150
  }
4151
+ interface ReactiveControllerHost$1 {
4152
+ /**
4153
+ * Adds a controller to the host, which sets up the controller's lifecycle
4154
+ * methods to be called with the host's lifecycle.
4155
+ */
4156
+ addController(controller: ReactiveController$1): void;
4157
+ /**
4158
+ * Removes a controller from the host.
4159
+ */
4160
+ removeController(controller: ReactiveController$1): void;
4161
+ /**
4162
+ * Requests a host update which is processed asynchronously. The update can
4163
+ * be waited on via the `updateComplete` property.
4164
+ */
4165
+ requestUpdate(): void;
4166
+ /**
4167
+ * Returns a Promise that resolves when the host has completed updating.
4168
+ * The Promise value is a boolean that is `true` if the element completed the
4169
+ * update without triggering another update. The Promise result is `false` if
4170
+ * a property was set inside `updated()`. If the Promise is rejected, an
4171
+ * exception was thrown during the update.
4172
+ *
4173
+ * @return A promise of a boolean that indicates if the update resolved
4174
+ * without triggering another update.
4175
+ */
4176
+ readonly updateComplete: Promise<boolean>;
4177
+ }
4178
+ interface ReactiveController$1 {
4179
+ /**
4180
+ * Called when the host is connected to the component tree. For custom
4181
+ * element hosts, this corresponds to the `connectedCallback()` lifecycle,
4182
+ * which is only called when the component is connected to the document.
4183
+ */
4184
+ hostConnected?(): void;
4185
+ /**
4186
+ * Called when the host is disconnected from the component tree. For custom
4187
+ * element hosts, this corresponds to the `disconnectedCallback()` lifecycle,
4188
+ * which is called the host or an ancestor component is disconnected from the
4189
+ * document.
4190
+ */
4191
+ hostDisconnected?(): void;
4192
+ /**
4193
+ * Called during the client-side host update, just before the host calls
4194
+ * its own update.
4195
+ *
4196
+ * Code in `update()` can depend on the DOM as it is not called in
4197
+ * server-side rendering.
4198
+ */
4199
+ hostUpdate?(): void;
4200
+ /**
4201
+ * Called after a host update, just before the host calls firstUpdated and
4202
+ * updated. It is not called in server-side rendering.
4203
+ *
4204
+ */
4205
+ hostUpdated?(): void;
4206
+ }
3945
4207
  export interface TaskFunctionOptions {
3946
4208
  signal: AbortSignal;
3947
4209
  }
@@ -4036,8 +4298,8 @@ declare class Task<const T extends ReadonlyArray<unknown> = ReadonlyArray<unknow
4036
4298
  private _resolveTaskComplete?;
4037
4299
  private _rejectTaskComplete?;
4038
4300
  private _taskComplete?;
4039
- constructor(host: ReactiveControllerHost, task: TaskConfig<T, R>);
4040
- constructor(host: ReactiveControllerHost, task: TaskFunction<T, R>, args?: ArgsFunction<T>);
4301
+ constructor(host: ReactiveControllerHost$1, task: TaskConfig<T, R>);
4302
+ constructor(host: ReactiveControllerHost$1, task: TaskFunction<T, R>, args?: ArgsFunction<T>);
4041
4303
  hostUpdate(): void;
4042
4304
  hostUpdated(): void;
4043
4305
  private _getArgs;
@@ -4572,11 +4834,6 @@ declare global {
4572
4834
  * @returns {Promise<void>} A promise that resolves when loading is complete
4573
4835
  */
4574
4836
  export declare function loadPrimer(): Promise<void>;
4575
- declare global {
4576
- interface HTMLElementTagNameMap {
4577
- "primer-checkout": PrimerCheckoutComponent;
4578
- }
4579
- }
4580
4837
 
4581
4838
  export {
4582
4839
  AchPaymentComponent as AchPayment,