@inttegro/svelte 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,13 @@
1
+ # `@inttegro/svelte`
2
+
3
+ Svelte 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
+ ```svelte
8
+ <script lang="ts">
9
+ import { Checkout } from '@inttegro/svelte'
10
+ </script>
11
+
12
+ <Checkout {orderId} onCompleted={() => location.assign('/complete')} />
13
+ ```
@@ -0,0 +1,86 @@
1
+ <script lang="ts">
2
+ import {
3
+ loadInttegro,
4
+ type CheckoutController,
5
+ type CheckoutEvent,
6
+ } from '@inttegro/js'
7
+ import { untrack } from 'svelte'
8
+ import type { CheckoutProps } from './types'
9
+
10
+ let {
11
+ appearance,
12
+ class: className,
13
+ locale,
14
+ onCompleted,
15
+ onError,
16
+ onEvent,
17
+ onReady,
18
+ orderId,
19
+ timeout,
20
+ title,
21
+ }: CheckoutProps = $props()
22
+
23
+ let container: HTMLDivElement
24
+ let checkout = $state<CheckoutController>()
25
+
26
+ $effect(() => {
27
+ const identity = { orderId, timeout, title }
28
+ if (!container) return
29
+
30
+ let active = true
31
+ let instance: CheckoutController | undefined
32
+ let unsubscribe: (() => void) | undefined
33
+
34
+ void loadInttegro()
35
+ .then(async (inttegro) => {
36
+ if (!active || !inttegro) return
37
+ instance = inttegro.createCheckout(
38
+ definedOptions({
39
+ ...identity,
40
+ appearance: untrack(() => appearance),
41
+ locale: untrack(() => locale),
42
+ }),
43
+ )
44
+ if (!active) {
45
+ instance.destroy()
46
+ return
47
+ }
48
+ checkout = instance
49
+ unsubscribe = instance.onEvent((event) => {
50
+ onEvent?.(event)
51
+ if (event.type === 'ready') onReady?.(event)
52
+ if (event.type === 'completed') onCompleted?.(event)
53
+ if (event.type === 'error') onError?.(event)
54
+ })
55
+ await instance.mount(container)
56
+ })
57
+ .catch((error: unknown) => {
58
+ if (active) {
59
+ onError?.(
60
+ error instanceof Error
61
+ ? error
62
+ : new Error('Checkout failed to load.'),
63
+ )
64
+ }
65
+ })
66
+
67
+ return () => {
68
+ active = false
69
+ unsubscribe?.()
70
+ instance?.destroy()
71
+ if (checkout === instance) checkout = undefined
72
+ }
73
+ })
74
+
75
+ $effect(() => {
76
+ checkout?.update(definedOptions({ appearance, locale }))
77
+ })
78
+
79
+ function definedOptions<Value extends object>(options: Value): Value {
80
+ return Object.fromEntries(
81
+ Object.entries(options).filter(([, value]) => value !== undefined),
82
+ ) as Value
83
+ }
84
+ </script>
85
+
86
+ <div bind:this={container} class={className}></div>
@@ -0,0 +1,4 @@
1
+ import type { CheckoutProps } from './types';
2
+ declare const Checkout: import("svelte").Component<CheckoutProps, {}, "">;
3
+ type Checkout = ReturnType<typeof Checkout>;
4
+ export default Checkout;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Svelte component adapter for Inttegro-hosted Checkout.
3
+ *
4
+ * `Checkout` loads the runtime in a browser effect and destroys its controller
5
+ * when the component leaves the page. Keep it mounted while a payment attempt
6
+ * or external confirmation is pending.
7
+ *
8
+ * @example
9
+ * ```svelte
10
+ * <script lang="ts">
11
+ * import { Checkout } from '@inttegro/svelte'
12
+ * let { orderId }: { orderId: string } = $props()
13
+ * </script>
14
+ *
15
+ * <Checkout
16
+ * {orderId}
17
+ * appearance={{ theme: 'system' }}
18
+ * onCompleted={() => location.assign('/orders/complete')}
19
+ * onError={reportCheckoutError}
20
+ * />
21
+ * ```
22
+ *
23
+ * @module @inttegro/svelte
24
+ */
25
+ export { default as Checkout } from './Checkout.svelte';
26
+ export type { CheckoutProps } from './types';
27
+ export type { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutTheme, } from '@inttegro/js';
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Svelte component adapter for Inttegro-hosted Checkout.
3
+ *
4
+ * `Checkout` loads the runtime in a browser effect and destroys its controller
5
+ * when the component leaves the page. Keep it mounted while a payment attempt
6
+ * or external confirmation is pending.
7
+ *
8
+ * @example
9
+ * ```svelte
10
+ * <script lang="ts">
11
+ * import { Checkout } from '@inttegro/svelte'
12
+ * let { orderId }: { orderId: string } = $props()
13
+ * </script>
14
+ *
15
+ * <Checkout
16
+ * {orderId}
17
+ * appearance={{ theme: 'system' }}
18
+ * onCompleted={() => location.assign('/orders/complete')}
19
+ * onError={reportCheckoutError}
20
+ * />
21
+ * ```
22
+ *
23
+ * @module @inttegro/svelte
24
+ */
25
+ export { default as Checkout } from './Checkout.svelte';
@@ -0,0 +1,39 @@
1
+ import type { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent } from '@inttegro/js';
2
+ /**
3
+ * Props accepted by the Inttegro {@link Checkout} component.
4
+ *
5
+ * `orderId`, `timeout`, and `title` identify a hosted experience; changing one
6
+ * destroys the current controller and mounts a new one. `appearance` and
7
+ * `locale` update the current controller in place.
8
+ *
9
+ * @category Svelte
10
+ */
11
+ export interface CheckoutProps {
12
+ /** Initial and reactive theme preference for hosted Checkout. */
13
+ appearance?: CheckoutAppearance | undefined;
14
+ /** CSS class applied to the outer container owned by your Svelte application. */
15
+ class?: string | undefined;
16
+ /** Initial and reactive BCP 47 locale preference. */
17
+ locale?: string | undefined;
18
+ /**
19
+ * Called after the successful hosted terminal state. Reconcile the Order on
20
+ * your server before fulfillment.
21
+ */
22
+ onCompleted?: ((event: Extract<CheckoutEvent, {
23
+ type: 'completed';
24
+ }>) => void) | undefined;
25
+ /** Called for loader/mount failures and sanitized hosted errors. */
26
+ onError?: ((event: CheckoutErrorEvent | Error) => void) | undefined;
27
+ /** Called for every sanitized lifecycle event. */
28
+ onEvent?: ((event: CheckoutEvent) => void) | undefined;
29
+ /** Called once Checkout is initialized and interactive. */
30
+ onReady?: ((event: Extract<CheckoutEvent, {
31
+ type: 'ready';
32
+ }>) => void) | undefined;
33
+ /** Client-safe reference for the finalized Order being paid. */
34
+ orderId: string;
35
+ /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */
36
+ timeout?: number | undefined;
37
+ /** Accessible iframe title; defaults to `Checkout`. */
38
+ title?: string | undefined;
39
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@inttegro/svelte",
3
+ "version": "0.1.0",
4
+ "description": "Svelte components for Inttegro hosted workflows",
5
+ "type": "module",
6
+ "svelte": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "svelte": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "sideEffects": false,
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "scripts": {
25
+ "build": "svelte-package -i src -o dist",
26
+ "typecheck": "svelte-check --tsconfig ./tsconfig.json"
27
+ },
28
+ "dependencies": {
29
+ "@inttegro/js": "0.1.0"
30
+ },
31
+ "peerDependencies": {
32
+ "svelte": ">=5"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/zebodotdev/js.git",
37
+ "directory": "packages/svelte"
38
+ },
39
+ "homepage": "https://studio.inttegro.com/web/svelte",
40
+ "author": "Inttegro Eng <engineering@inttegro.com> (https://inttegro.com)",
41
+ "license": "MIT",
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "provenance": true
45
+ },
46
+ "typedocOptions": {
47
+ "entryPoints": [
48
+ "dist/index.d.ts"
49
+ ],
50
+ "tsconfig": "typedoc.tsconfig.json"
51
+ },
52
+ "devDependencies": {
53
+ "@sveltejs/package": "2.5.8",
54
+ "svelte": "5.57.0",
55
+ "svelte-check": "4.7.6",
56
+ "typescript": "6.0.3"
57
+ }
58
+ }