@inttegro/vue 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Inttegro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # `@inttegro/vue`
2
+
3
+ Vue adapter for Inttegro hosted workflows. The component automatically uses
4
+ `@inttegro/js` to load the executable runtime from Inttegro's fixed origin; it
5
+ does not bundle the payment-collection runtime.
6
+
7
+ ```vue
8
+ <script setup lang="ts">
9
+ import { Checkout } from '@inttegro/vue'
10
+ </script>
11
+
12
+ <template>
13
+ <Checkout :order-id="orderId" @completed="onCompleted" />
14
+ </template>
15
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Checkout: () => Checkout
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/Checkout.ts
28
+ var import_js = require("@inttegro/js");
29
+ var import_vue = require("vue");
30
+ var Checkout = (0, import_vue.defineComponent)({
31
+ name: "InttegroCheckout",
32
+ props: {
33
+ appearance: Object,
34
+ locale: String,
35
+ orderId: { type: String, required: true },
36
+ timeout: Number,
37
+ title: String
38
+ },
39
+ emits: {
40
+ completed: (_event) => true,
41
+ error: (_event) => true,
42
+ event: (_event) => true,
43
+ ready: (_event) => true
44
+ },
45
+ setup(props, { emit, expose }) {
46
+ const container = (0, import_vue.ref)();
47
+ let checkout;
48
+ let unsubscribe;
49
+ let generation = 0;
50
+ function destroyCheckout() {
51
+ generation += 1;
52
+ unsubscribe?.();
53
+ unsubscribe = void 0;
54
+ checkout?.destroy();
55
+ checkout = void 0;
56
+ }
57
+ async function mountCheckout() {
58
+ destroyCheckout();
59
+ const target = container.value;
60
+ const currentGeneration = generation;
61
+ if (!target) return;
62
+ try {
63
+ const inttegro = await (0, import_js.loadInttegro)();
64
+ if (generation !== currentGeneration || !inttegro) return;
65
+ const instance = inttegro.createCheckout(
66
+ definedOptions({
67
+ appearance: props.appearance,
68
+ locale: props.locale,
69
+ orderId: props.orderId,
70
+ timeout: props.timeout,
71
+ title: props.title
72
+ })
73
+ );
74
+ if (generation !== currentGeneration) {
75
+ instance.destroy();
76
+ return;
77
+ }
78
+ checkout = instance;
79
+ unsubscribe = instance.onEvent((event) => {
80
+ emit("event", event);
81
+ if (event.type === "ready") emit("ready", event);
82
+ if (event.type === "completed") emit("completed", event);
83
+ if (event.type === "error") emit("error", event);
84
+ });
85
+ await instance.mount(target);
86
+ } catch (error) {
87
+ if (generation !== currentGeneration) return;
88
+ emit(
89
+ "error",
90
+ error instanceof Error ? error : new Error("Checkout failed to load.")
91
+ );
92
+ }
93
+ }
94
+ (0, import_vue.onMounted)(mountCheckout);
95
+ (0, import_vue.onBeforeUnmount)(destroyCheckout);
96
+ (0, import_vue.watch)(
97
+ () => [props.orderId, props.timeout, props.title],
98
+ () => void mountCheckout()
99
+ );
100
+ (0, import_vue.watch)(
101
+ () => [props.appearance, props.locale],
102
+ ([appearance, locale]) => {
103
+ checkout?.update(definedOptions({ appearance, locale }));
104
+ },
105
+ { deep: true }
106
+ );
107
+ expose({
108
+ focus: () => checkout?.focus(),
109
+ update: (options) => checkout?.update(options)
110
+ });
111
+ return () => (0, import_vue.h)("div", { ref: container });
112
+ }
113
+ });
114
+ function definedOptions(options) {
115
+ return Object.fromEntries(
116
+ Object.entries(options).filter(([, value]) => value !== void 0)
117
+ );
118
+ }
119
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/Checkout.ts"],"sourcesContent":["/**\n * Vue component adapter for Inttegro-hosted Checkout.\n *\n * @module @inttegro/vue\n */\nexport { Checkout, type CheckoutExposed, type CheckoutProps } from './Checkout'\nexport type {\n CheckoutAppearance,\n CheckoutErrorEvent,\n CheckoutEvent,\n CheckoutTheme,\n} from '@inttegro/js'\n","import {\n loadInttegro,\n type CheckoutAppearance,\n type CheckoutController,\n type CheckoutErrorEvent,\n type CheckoutEvent,\n} from '@inttegro/js'\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n type PropType,\n} from 'vue'\n\n/**\n * Props accepted by the Inttegro {@link Checkout} component.\n *\n * Changing `orderId`, `timeout`, or `title` replaces the hosted controller.\n * Changing `appearance` or `locale` updates it in place, preserving payer\n * progress where the hosted flow permits.\n *\n * @category Vue\n */\nexport interface CheckoutProps {\n /** Initial and reactive theme preference for hosted Checkout. */\n appearance?: CheckoutAppearance | undefined\n /** Initial and reactive BCP 47 locale preference. */\n locale?: string | undefined\n /** Client-safe reference for the finalized Order being paid. */\n orderId: string\n /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */\n timeout?: number | undefined\n /** Accessible iframe title; defaults to `Checkout`. */\n title?: string | undefined\n}\n\n/**\n * Imperative operations exposed by {@link Checkout} through a Vue template ref.\n *\n * @category Vue\n */\nexport interface CheckoutExposed {\n /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when a controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Embeds Inttegro-hosted Checkout in a Vue application.\n *\n * The component owns the loader and controller lifecycle. It emits:\n *\n * - `ready` once the iframe is interactive;\n * - `event` for every sanitized Checkout lifecycle event;\n * - `completed` at the successful hosted terminal state; and\n * - `error` for loader/mount failures or sanitized hosted errors.\n *\n * Keep the component mounted while payment or confirmation is pending. On\n * unmount it removes its event subscription and permanently destroys the\n * controller.\n *\n * @example Use native Vue events\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { Checkout, type CheckoutExposed } from '@inttegro/vue'\n *\n * const props = defineProps<{ orderId: string }>()\n * const checkout = ref<CheckoutExposed>()\n * </script>\n *\n * <template>\n * <Checkout\n * ref=\"checkout\"\n * :order-id=\"props.orderId\"\n * :appearance=\"{ theme: 'system' }\"\n * @ready=\"checkout?.focus()\"\n * @completed=\"$router.push('/orders/complete')\"\n * @error=\"reportCheckoutError\"\n * />\n * </template>\n * ```\n *\n * @category Vue\n */\nexport const Checkout = defineComponent({\n name: 'InttegroCheckout',\n props: {\n appearance: Object as PropType<CheckoutAppearance>,\n locale: String,\n orderId: { type: String, required: true },\n timeout: Number,\n title: String,\n },\n emits: {\n completed: (_event: Extract<CheckoutEvent, { type: 'completed' }>) => true,\n error: (_event: CheckoutErrorEvent | Error) => true,\n event: (_event: CheckoutEvent) => true,\n ready: (_event: Extract<CheckoutEvent, { type: 'ready' }>) => true,\n },\n setup(props, { emit, expose }) {\n const container = ref<HTMLElement>()\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n let generation = 0\n\n function destroyCheckout() {\n generation += 1\n unsubscribe?.()\n unsubscribe = undefined\n checkout?.destroy()\n checkout = undefined\n }\n\n async function mountCheckout() {\n destroyCheckout()\n const target = container.value\n const currentGeneration = generation\n if (!target) return\n try {\n const inttegro = await loadInttegro()\n if (generation !== currentGeneration || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n appearance: props.appearance,\n locale: props.locale,\n orderId: props.orderId,\n timeout: props.timeout,\n title: props.title,\n }),\n )\n if (generation !== currentGeneration) {\n instance.destroy()\n return\n }\n checkout = instance\n unsubscribe = instance.onEvent((event) => {\n emit('event', event)\n if (event.type === 'ready') emit('ready', event)\n if (event.type === 'completed') emit('completed', event)\n if (event.type === 'error') emit('error', event)\n })\n await instance.mount(target)\n } catch (error: unknown) {\n if (generation !== currentGeneration) return\n emit(\n 'error',\n error instanceof Error\n ? error\n : new Error('Checkout failed to load.'),\n )\n }\n }\n\n onMounted(mountCheckout)\n onBeforeUnmount(destroyCheckout)\n\n watch(\n () => [props.orderId, props.timeout, props.title],\n () => void mountCheckout(),\n )\n watch(\n () => [props.appearance, props.locale] as const,\n ([appearance, locale]) => {\n checkout?.update(definedOptions({ appearance, locale }))\n },\n { deep: true },\n )\n\n expose({\n focus: () => checkout?.focus(),\n update: (options: Parameters<CheckoutController['update']>[0]) =>\n checkout?.update(options),\n })\n\n return () => h('div', { ref: container })\n },\n})\n\nfunction definedOptions<Value extends object>(options: Value): Value {\n return Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined),\n ) as Value\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gBAMO;AACP,iBAQO;AA0EA,IAAM,eAAW,4BAAgB;AAAA,EACtC,MAAM;AAAA,EACN,OAAO;AAAA,IACL,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,SAAS,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACxC,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA,OAAO;AAAA,IACL,WAAW,CAAC,WAA0D;AAAA,IACtE,OAAO,CAAC,WAAuC;AAAA,IAC/C,OAAO,CAAC,WAA0B;AAAA,IAClC,OAAO,CAAC,WAAsD;AAAA,EAChE;AAAA,EACA,MAAM,OAAO,EAAE,MAAM,OAAO,GAAG;AAC7B,UAAM,gBAAY,gBAAiB;AACnC,QAAI;AACJ,QAAI;AACJ,QAAI,aAAa;AAEjB,aAAS,kBAAkB;AACzB,oBAAc;AACd,oBAAc;AACd,oBAAc;AACd,gBAAU,QAAQ;AAClB,iBAAW;AAAA,IACb;AAEA,mBAAe,gBAAgB;AAC7B,sBAAgB;AAChB,YAAM,SAAS,UAAU;AACzB,YAAM,oBAAoB;AAC1B,UAAI,CAAC,OAAQ;AACb,UAAI;AACF,cAAM,WAAW,UAAM,wBAAa;AACpC,YAAI,eAAe,qBAAqB,CAAC,SAAU;AACnD,cAAM,WAAW,SAAS;AAAA,UACxB,eAAe;AAAA,YACb,YAAY,MAAM;AAAA,YAClB,QAAQ,MAAM;AAAA,YACd,SAAS,MAAM;AAAA,YACf,SAAS,MAAM;AAAA,YACf,OAAO,MAAM;AAAA,UACf,CAAC;AAAA,QACH;AACA,YAAI,eAAe,mBAAmB;AACpC,mBAAS,QAAQ;AACjB;AAAA,QACF;AACA,mBAAW;AACX,sBAAc,SAAS,QAAQ,CAAC,UAAU;AACxC,eAAK,SAAS,KAAK;AACnB,cAAI,MAAM,SAAS,QAAS,MAAK,SAAS,KAAK;AAC/C,cAAI,MAAM,SAAS,YAAa,MAAK,aAAa,KAAK;AACvD,cAAI,MAAM,SAAS,QAAS,MAAK,SAAS,KAAK;AAAA,QACjD,CAAC;AACD,cAAM,SAAS,MAAM,MAAM;AAAA,MAC7B,SAAS,OAAgB;AACvB,YAAI,eAAe,kBAAmB;AACtC;AAAA,UACE;AAAA,UACA,iBAAiB,QACb,QACA,IAAI,MAAM,0BAA0B;AAAA,QAC1C;AAAA,MACF;AAAA,IACF;AAEA,8BAAU,aAAa;AACvB,oCAAgB,eAAe;AAE/B;AAAA,MACE,MAAM,CAAC,MAAM,SAAS,MAAM,SAAS,MAAM,KAAK;AAAA,MAChD,MAAM,KAAK,cAAc;AAAA,IAC3B;AACA;AAAA,MACE,MAAM,CAAC,MAAM,YAAY,MAAM,MAAM;AAAA,MACrC,CAAC,CAAC,YAAY,MAAM,MAAM;AACxB,kBAAU,OAAO,eAAe,EAAE,YAAY,OAAO,CAAC,CAAC;AAAA,MACzD;AAAA,MACA,EAAE,MAAM,KAAK;AAAA,IACf;AAEA,WAAO;AAAA,MACL,OAAO,MAAM,UAAU,MAAM;AAAA,MAC7B,QAAQ,CAAC,YACP,UAAU,OAAO,OAAO;AAAA,IAC5B,CAAC;AAED,WAAO,UAAM,cAAE,OAAO,EAAE,KAAK,UAAU,CAAC;AAAA,EAC1C;AACF,CAAC;AAED,SAAS,eAAqC,SAAuB;AACnE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;","names":[]}
@@ -0,0 +1,113 @@
1
+ import * as _inttegro_js from '@inttegro/js';
2
+ import { CheckoutAppearance, CheckoutEvent, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
3
+ export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutTheme } from '@inttegro/js';
4
+ import * as vue from 'vue';
5
+ import { PropType } from 'vue';
6
+
7
+ /**
8
+ * Props accepted by the Inttegro {@link Checkout} component.
9
+ *
10
+ * Changing `orderId`, `timeout`, or `title` replaces the hosted controller.
11
+ * Changing `appearance` or `locale` updates it in place, preserving payer
12
+ * progress where the hosted flow permits.
13
+ *
14
+ * @category Vue
15
+ */
16
+ interface CheckoutProps {
17
+ /** Initial and reactive theme preference for hosted Checkout. */
18
+ appearance?: CheckoutAppearance | undefined;
19
+ /** Initial and reactive BCP 47 locale preference. */
20
+ locale?: string | undefined;
21
+ /** Client-safe reference for the finalized Order being paid. */
22
+ orderId: string;
23
+ /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */
24
+ timeout?: number | undefined;
25
+ /** Accessible iframe title; defaults to `Checkout`. */
26
+ title?: string | undefined;
27
+ }
28
+ /**
29
+ * Imperative operations exposed by {@link Checkout} through a Vue template ref.
30
+ *
31
+ * @category Vue
32
+ */
33
+ interface CheckoutExposed {
34
+ /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */
35
+ focus(): void;
36
+ /** Applies a new locale or theme when a controller exists. */
37
+ update(options: Parameters<CheckoutController['update']>[0]): void;
38
+ }
39
+ /**
40
+ * Embeds Inttegro-hosted Checkout in a Vue application.
41
+ *
42
+ * The component owns the loader and controller lifecycle. It emits:
43
+ *
44
+ * - `ready` once the iframe is interactive;
45
+ * - `event` for every sanitized Checkout lifecycle event;
46
+ * - `completed` at the successful hosted terminal state; and
47
+ * - `error` for loader/mount failures or sanitized hosted errors.
48
+ *
49
+ * Keep the component mounted while payment or confirmation is pending. On
50
+ * unmount it removes its event subscription and permanently destroys the
51
+ * controller.
52
+ *
53
+ * @example Use native Vue events
54
+ * ```vue
55
+ * <script setup lang="ts">
56
+ * import { ref } from 'vue'
57
+ * import { Checkout, type CheckoutExposed } from '@inttegro/vue'
58
+ *
59
+ * const props = defineProps<{ orderId: string }>()
60
+ * const checkout = ref<CheckoutExposed>()
61
+ * </script>
62
+ *
63
+ * <template>
64
+ * <Checkout
65
+ * ref="checkout"
66
+ * :order-id="props.orderId"
67
+ * :appearance="{ theme: 'system' }"
68
+ * @ready="checkout?.focus()"
69
+ * @completed="$router.push('/orders/complete')"
70
+ * @error="reportCheckoutError"
71
+ * />
72
+ * </template>
73
+ * ```
74
+ *
75
+ * @category Vue
76
+ */
77
+ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
78
+ appearance: PropType<CheckoutAppearance>;
79
+ locale: StringConstructor;
80
+ orderId: {
81
+ type: StringConstructor;
82
+ required: true;
83
+ };
84
+ timeout: NumberConstructor;
85
+ title: StringConstructor;
86
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
87
+ [key: string]: any;
88
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
89
+ completed: (_event: Extract<CheckoutEvent, {
90
+ type: "completed";
91
+ }>) => true;
92
+ error: (_event: CheckoutErrorEvent | Error) => true;
93
+ event: (_event: CheckoutEvent) => true;
94
+ ready: (_event: Extract<CheckoutEvent, {
95
+ type: "ready";
96
+ }>) => true;
97
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
98
+ appearance: PropType<CheckoutAppearance>;
99
+ locale: StringConstructor;
100
+ orderId: {
101
+ type: StringConstructor;
102
+ required: true;
103
+ };
104
+ timeout: NumberConstructor;
105
+ title: StringConstructor;
106
+ }>> & Readonly<{
107
+ onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
108
+ onReady?: (_event: _inttegro_js.CheckoutReadyEvent) => any;
109
+ onError?: (_event: CheckoutErrorEvent | Error) => any;
110
+ onEvent?: (_event: CheckoutEvent) => any;
111
+ }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
112
+
113
+ export { Checkout, type CheckoutExposed, type CheckoutProps };
@@ -0,0 +1,113 @@
1
+ import * as _inttegro_js from '@inttegro/js';
2
+ import { CheckoutAppearance, CheckoutEvent, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
3
+ export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutTheme } from '@inttegro/js';
4
+ import * as vue from 'vue';
5
+ import { PropType } from 'vue';
6
+
7
+ /**
8
+ * Props accepted by the Inttegro {@link Checkout} component.
9
+ *
10
+ * Changing `orderId`, `timeout`, or `title` replaces the hosted controller.
11
+ * Changing `appearance` or `locale` updates it in place, preserving payer
12
+ * progress where the hosted flow permits.
13
+ *
14
+ * @category Vue
15
+ */
16
+ interface CheckoutProps {
17
+ /** Initial and reactive theme preference for hosted Checkout. */
18
+ appearance?: CheckoutAppearance | undefined;
19
+ /** Initial and reactive BCP 47 locale preference. */
20
+ locale?: string | undefined;
21
+ /** Client-safe reference for the finalized Order being paid. */
22
+ orderId: string;
23
+ /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */
24
+ timeout?: number | undefined;
25
+ /** Accessible iframe title; defaults to `Checkout`. */
26
+ title?: string | undefined;
27
+ }
28
+ /**
29
+ * Imperative operations exposed by {@link Checkout} through a Vue template ref.
30
+ *
31
+ * @category Vue
32
+ */
33
+ interface CheckoutExposed {
34
+ /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */
35
+ focus(): void;
36
+ /** Applies a new locale or theme when a controller exists. */
37
+ update(options: Parameters<CheckoutController['update']>[0]): void;
38
+ }
39
+ /**
40
+ * Embeds Inttegro-hosted Checkout in a Vue application.
41
+ *
42
+ * The component owns the loader and controller lifecycle. It emits:
43
+ *
44
+ * - `ready` once the iframe is interactive;
45
+ * - `event` for every sanitized Checkout lifecycle event;
46
+ * - `completed` at the successful hosted terminal state; and
47
+ * - `error` for loader/mount failures or sanitized hosted errors.
48
+ *
49
+ * Keep the component mounted while payment or confirmation is pending. On
50
+ * unmount it removes its event subscription and permanently destroys the
51
+ * controller.
52
+ *
53
+ * @example Use native Vue events
54
+ * ```vue
55
+ * <script setup lang="ts">
56
+ * import { ref } from 'vue'
57
+ * import { Checkout, type CheckoutExposed } from '@inttegro/vue'
58
+ *
59
+ * const props = defineProps<{ orderId: string }>()
60
+ * const checkout = ref<CheckoutExposed>()
61
+ * </script>
62
+ *
63
+ * <template>
64
+ * <Checkout
65
+ * ref="checkout"
66
+ * :order-id="props.orderId"
67
+ * :appearance="{ theme: 'system' }"
68
+ * @ready="checkout?.focus()"
69
+ * @completed="$router.push('/orders/complete')"
70
+ * @error="reportCheckoutError"
71
+ * />
72
+ * </template>
73
+ * ```
74
+ *
75
+ * @category Vue
76
+ */
77
+ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
78
+ appearance: PropType<CheckoutAppearance>;
79
+ locale: StringConstructor;
80
+ orderId: {
81
+ type: StringConstructor;
82
+ required: true;
83
+ };
84
+ timeout: NumberConstructor;
85
+ title: StringConstructor;
86
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
87
+ [key: string]: any;
88
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
89
+ completed: (_event: Extract<CheckoutEvent, {
90
+ type: "completed";
91
+ }>) => true;
92
+ error: (_event: CheckoutErrorEvent | Error) => true;
93
+ event: (_event: CheckoutEvent) => true;
94
+ ready: (_event: Extract<CheckoutEvent, {
95
+ type: "ready";
96
+ }>) => true;
97
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
98
+ appearance: PropType<CheckoutAppearance>;
99
+ locale: StringConstructor;
100
+ orderId: {
101
+ type: StringConstructor;
102
+ required: true;
103
+ };
104
+ timeout: NumberConstructor;
105
+ title: StringConstructor;
106
+ }>> & Readonly<{
107
+ onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
108
+ onReady?: (_event: _inttegro_js.CheckoutReadyEvent) => any;
109
+ onError?: (_event: CheckoutErrorEvent | Error) => any;
110
+ onEvent?: (_event: CheckoutEvent) => any;
111
+ }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
112
+
113
+ export { Checkout, type CheckoutExposed, type CheckoutProps };
package/dist/index.js ADDED
@@ -0,0 +1,105 @@
1
+ // src/Checkout.ts
2
+ import {
3
+ loadInttegro
4
+ } from "@inttegro/js";
5
+ import {
6
+ defineComponent,
7
+ h,
8
+ onBeforeUnmount,
9
+ onMounted,
10
+ ref,
11
+ watch
12
+ } from "vue";
13
+ var Checkout = defineComponent({
14
+ name: "InttegroCheckout",
15
+ props: {
16
+ appearance: Object,
17
+ locale: String,
18
+ orderId: { type: String, required: true },
19
+ timeout: Number,
20
+ title: String
21
+ },
22
+ emits: {
23
+ completed: (_event) => true,
24
+ error: (_event) => true,
25
+ event: (_event) => true,
26
+ ready: (_event) => true
27
+ },
28
+ setup(props, { emit, expose }) {
29
+ const container = ref();
30
+ let checkout;
31
+ let unsubscribe;
32
+ let generation = 0;
33
+ function destroyCheckout() {
34
+ generation += 1;
35
+ unsubscribe?.();
36
+ unsubscribe = void 0;
37
+ checkout?.destroy();
38
+ checkout = void 0;
39
+ }
40
+ async function mountCheckout() {
41
+ destroyCheckout();
42
+ const target = container.value;
43
+ const currentGeneration = generation;
44
+ if (!target) return;
45
+ try {
46
+ const inttegro = await loadInttegro();
47
+ if (generation !== currentGeneration || !inttegro) return;
48
+ const instance = inttegro.createCheckout(
49
+ definedOptions({
50
+ appearance: props.appearance,
51
+ locale: props.locale,
52
+ orderId: props.orderId,
53
+ timeout: props.timeout,
54
+ title: props.title
55
+ })
56
+ );
57
+ if (generation !== currentGeneration) {
58
+ instance.destroy();
59
+ return;
60
+ }
61
+ checkout = instance;
62
+ unsubscribe = instance.onEvent((event) => {
63
+ emit("event", event);
64
+ if (event.type === "ready") emit("ready", event);
65
+ if (event.type === "completed") emit("completed", event);
66
+ if (event.type === "error") emit("error", event);
67
+ });
68
+ await instance.mount(target);
69
+ } catch (error) {
70
+ if (generation !== currentGeneration) return;
71
+ emit(
72
+ "error",
73
+ error instanceof Error ? error : new Error("Checkout failed to load.")
74
+ );
75
+ }
76
+ }
77
+ onMounted(mountCheckout);
78
+ onBeforeUnmount(destroyCheckout);
79
+ watch(
80
+ () => [props.orderId, props.timeout, props.title],
81
+ () => void mountCheckout()
82
+ );
83
+ watch(
84
+ () => [props.appearance, props.locale],
85
+ ([appearance, locale]) => {
86
+ checkout?.update(definedOptions({ appearance, locale }));
87
+ },
88
+ { deep: true }
89
+ );
90
+ expose({
91
+ focus: () => checkout?.focus(),
92
+ update: (options) => checkout?.update(options)
93
+ });
94
+ return () => h("div", { ref: container });
95
+ }
96
+ });
97
+ function definedOptions(options) {
98
+ return Object.fromEntries(
99
+ Object.entries(options).filter(([, value]) => value !== void 0)
100
+ );
101
+ }
102
+ export {
103
+ Checkout
104
+ };
105
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Checkout.ts"],"sourcesContent":["import {\n loadInttegro,\n type CheckoutAppearance,\n type CheckoutController,\n type CheckoutErrorEvent,\n type CheckoutEvent,\n} from '@inttegro/js'\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n type PropType,\n} from 'vue'\n\n/**\n * Props accepted by the Inttegro {@link Checkout} component.\n *\n * Changing `orderId`, `timeout`, or `title` replaces the hosted controller.\n * Changing `appearance` or `locale` updates it in place, preserving payer\n * progress where the hosted flow permits.\n *\n * @category Vue\n */\nexport interface CheckoutProps {\n /** Initial and reactive theme preference for hosted Checkout. */\n appearance?: CheckoutAppearance | undefined\n /** Initial and reactive BCP 47 locale preference. */\n locale?: string | undefined\n /** Client-safe reference for the finalized Order being paid. */\n orderId: string\n /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */\n timeout?: number | undefined\n /** Accessible iframe title; defaults to `Checkout`. */\n title?: string | undefined\n}\n\n/**\n * Imperative operations exposed by {@link Checkout} through a Vue template ref.\n *\n * @category Vue\n */\nexport interface CheckoutExposed {\n /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when a controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Embeds Inttegro-hosted Checkout in a Vue application.\n *\n * The component owns the loader and controller lifecycle. It emits:\n *\n * - `ready` once the iframe is interactive;\n * - `event` for every sanitized Checkout lifecycle event;\n * - `completed` at the successful hosted terminal state; and\n * - `error` for loader/mount failures or sanitized hosted errors.\n *\n * Keep the component mounted while payment or confirmation is pending. On\n * unmount it removes its event subscription and permanently destroys the\n * controller.\n *\n * @example Use native Vue events\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { Checkout, type CheckoutExposed } from '@inttegro/vue'\n *\n * const props = defineProps<{ orderId: string }>()\n * const checkout = ref<CheckoutExposed>()\n * </script>\n *\n * <template>\n * <Checkout\n * ref=\"checkout\"\n * :order-id=\"props.orderId\"\n * :appearance=\"{ theme: 'system' }\"\n * @ready=\"checkout?.focus()\"\n * @completed=\"$router.push('/orders/complete')\"\n * @error=\"reportCheckoutError\"\n * />\n * </template>\n * ```\n *\n * @category Vue\n */\nexport const Checkout = defineComponent({\n name: 'InttegroCheckout',\n props: {\n appearance: Object as PropType<CheckoutAppearance>,\n locale: String,\n orderId: { type: String, required: true },\n timeout: Number,\n title: String,\n },\n emits: {\n completed: (_event: Extract<CheckoutEvent, { type: 'completed' }>) => true,\n error: (_event: CheckoutErrorEvent | Error) => true,\n event: (_event: CheckoutEvent) => true,\n ready: (_event: Extract<CheckoutEvent, { type: 'ready' }>) => true,\n },\n setup(props, { emit, expose }) {\n const container = ref<HTMLElement>()\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n let generation = 0\n\n function destroyCheckout() {\n generation += 1\n unsubscribe?.()\n unsubscribe = undefined\n checkout?.destroy()\n checkout = undefined\n }\n\n async function mountCheckout() {\n destroyCheckout()\n const target = container.value\n const currentGeneration = generation\n if (!target) return\n try {\n const inttegro = await loadInttegro()\n if (generation !== currentGeneration || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n appearance: props.appearance,\n locale: props.locale,\n orderId: props.orderId,\n timeout: props.timeout,\n title: props.title,\n }),\n )\n if (generation !== currentGeneration) {\n instance.destroy()\n return\n }\n checkout = instance\n unsubscribe = instance.onEvent((event) => {\n emit('event', event)\n if (event.type === 'ready') emit('ready', event)\n if (event.type === 'completed') emit('completed', event)\n if (event.type === 'error') emit('error', event)\n })\n await instance.mount(target)\n } catch (error: unknown) {\n if (generation !== currentGeneration) return\n emit(\n 'error',\n error instanceof Error\n ? error\n : new Error('Checkout failed to load.'),\n )\n }\n }\n\n onMounted(mountCheckout)\n onBeforeUnmount(destroyCheckout)\n\n watch(\n () => [props.orderId, props.timeout, props.title],\n () => void mountCheckout(),\n )\n watch(\n () => [props.appearance, props.locale] as const,\n ([appearance, locale]) => {\n checkout?.update(definedOptions({ appearance, locale }))\n },\n { deep: true },\n )\n\n expose({\n focus: () => checkout?.focus(),\n update: (options: Parameters<CheckoutController['update']>[0]) =>\n checkout?.update(options),\n })\n\n return () => h('div', { ref: container })\n },\n})\n\nfunction definedOptions<Value extends object>(options: Value): Value {\n return Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined),\n ) as Value\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA0EA,IAAM,WAAW,gBAAgB;AAAA,EACtC,MAAM;AAAA,EACN,OAAO;AAAA,IACL,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,SAAS,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACxC,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA,OAAO;AAAA,IACL,WAAW,CAAC,WAA0D;AAAA,IACtE,OAAO,CAAC,WAAuC;AAAA,IAC/C,OAAO,CAAC,WAA0B;AAAA,IAClC,OAAO,CAAC,WAAsD;AAAA,EAChE;AAAA,EACA,MAAM,OAAO,EAAE,MAAM,OAAO,GAAG;AAC7B,UAAM,YAAY,IAAiB;AACnC,QAAI;AACJ,QAAI;AACJ,QAAI,aAAa;AAEjB,aAAS,kBAAkB;AACzB,oBAAc;AACd,oBAAc;AACd,oBAAc;AACd,gBAAU,QAAQ;AAClB,iBAAW;AAAA,IACb;AAEA,mBAAe,gBAAgB;AAC7B,sBAAgB;AAChB,YAAM,SAAS,UAAU;AACzB,YAAM,oBAAoB;AAC1B,UAAI,CAAC,OAAQ;AACb,UAAI;AACF,cAAM,WAAW,MAAM,aAAa;AACpC,YAAI,eAAe,qBAAqB,CAAC,SAAU;AACnD,cAAM,WAAW,SAAS;AAAA,UACxB,eAAe;AAAA,YACb,YAAY,MAAM;AAAA,YAClB,QAAQ,MAAM;AAAA,YACd,SAAS,MAAM;AAAA,YACf,SAAS,MAAM;AAAA,YACf,OAAO,MAAM;AAAA,UACf,CAAC;AAAA,QACH;AACA,YAAI,eAAe,mBAAmB;AACpC,mBAAS,QAAQ;AACjB;AAAA,QACF;AACA,mBAAW;AACX,sBAAc,SAAS,QAAQ,CAAC,UAAU;AACxC,eAAK,SAAS,KAAK;AACnB,cAAI,MAAM,SAAS,QAAS,MAAK,SAAS,KAAK;AAC/C,cAAI,MAAM,SAAS,YAAa,MAAK,aAAa,KAAK;AACvD,cAAI,MAAM,SAAS,QAAS,MAAK,SAAS,KAAK;AAAA,QACjD,CAAC;AACD,cAAM,SAAS,MAAM,MAAM;AAAA,MAC7B,SAAS,OAAgB;AACvB,YAAI,eAAe,kBAAmB;AACtC;AAAA,UACE;AAAA,UACA,iBAAiB,QACb,QACA,IAAI,MAAM,0BAA0B;AAAA,QAC1C;AAAA,MACF;AAAA,IACF;AAEA,cAAU,aAAa;AACvB,oBAAgB,eAAe;AAE/B;AAAA,MACE,MAAM,CAAC,MAAM,SAAS,MAAM,SAAS,MAAM,KAAK;AAAA,MAChD,MAAM,KAAK,cAAc;AAAA,IAC3B;AACA;AAAA,MACE,MAAM,CAAC,MAAM,YAAY,MAAM,MAAM;AAAA,MACrC,CAAC,CAAC,YAAY,MAAM,MAAM;AACxB,kBAAU,OAAO,eAAe,EAAE,YAAY,OAAO,CAAC,CAAC;AAAA,MACzD;AAAA,MACA,EAAE,MAAM,KAAK;AAAA,IACf;AAEA,WAAO;AAAA,MACL,OAAO,MAAM,UAAU,MAAM;AAAA,MAC7B,QAAQ,CAAC,YACP,UAAU,OAAO,OAAO;AAAA,IAC5B,CAAC;AAED,WAAO,MAAM,EAAE,OAAO,EAAE,KAAK,UAAU,CAAC;AAAA,EAC1C;AACF,CAAC;AAED,SAAS,eAAqC,SAAuB;AACnE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@inttegro/vue",
3
+ "version": "0.1.0",
4
+ "description": "Vue components for Inttegro hosted workflows",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "sideEffects": false,
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "scripts": {
31
+ "build": "tsup",
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "dependencies": {
35
+ "@inttegro/js": "0.1.0"
36
+ },
37
+ "peerDependencies": {
38
+ "vue": ">=3.4"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/zebodotdev/js.git",
43
+ "directory": "packages/vue"
44
+ },
45
+ "homepage": "https://studio.inttegro.com/web/vue",
46
+ "author": "Inttegro Eng <engineering@inttegro.com> (https://inttegro.com)",
47
+ "license": "MIT",
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "provenance": true
51
+ },
52
+ "typedocOptions": {
53
+ "entryPoints": [
54
+ "src/index.ts"
55
+ ]
56
+ },
57
+ "devDependencies": {
58
+ "tsup": "8.5.1",
59
+ "typescript": "6.0.3",
60
+ "vue": "3.5.42"
61
+ }
62
+ }