@mochabug/adapt-astro 1.0.0-rc1
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/README.md +105 -0
- package/package.json +36 -0
- package/src/AdaptAutomation.astro +109 -0
- package/src/index.ts +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @mochabug/adapt-astro
|
|
2
|
+
|
|
3
|
+
Astro component for Adapt.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @mochabug/adapt-astro
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Requires Astro 3, 4, or 5.
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```astro
|
|
14
|
+
---
|
|
15
|
+
import AdaptAutomation from '@mochabug/adapt-astro/AdaptAutomation.astro';
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<AdaptAutomation id="auto-123" style="height: 600px;" />
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
If the automation requires authentication:
|
|
22
|
+
|
|
23
|
+
```astro
|
|
24
|
+
<AdaptAutomation id="auto-123" authToken="your-token" style="height: 600px;" />
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## SSR
|
|
28
|
+
|
|
29
|
+
Keep auth token on server. Enable SSR in astro.config.mjs:
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
// astro.config.mjs
|
|
33
|
+
export default defineConfig({
|
|
34
|
+
output: 'server'
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```astro
|
|
39
|
+
---
|
|
40
|
+
import AdaptAutomation from '@mochabug/adapt-astro/AdaptAutomation.astro';
|
|
41
|
+
import { startSession } from '@mochabug/adapt-core';
|
|
42
|
+
|
|
43
|
+
const authToken = await getAuthTokenFromBackend();
|
|
44
|
+
const { token } = await startSession({ id: 'auto-123' }, authToken);
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
<AdaptAutomation
|
|
48
|
+
id="auto-123"
|
|
49
|
+
sessionToken={token}
|
|
50
|
+
style="height: 600px;"
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Session inheritance
|
|
55
|
+
|
|
56
|
+
```astro
|
|
57
|
+
<!-- from URL hash: example.com#mb_session=xxx -->
|
|
58
|
+
<AdaptAutomation
|
|
59
|
+
id="auto-123"
|
|
60
|
+
inheritFrom={{ hash: 'mb_session' }}
|
|
61
|
+
/>
|
|
62
|
+
|
|
63
|
+
<!-- from URL param: example.com?token=xxx -->
|
|
64
|
+
<AdaptAutomation
|
|
65
|
+
id="auto-123"
|
|
66
|
+
inheritFrom={{ param: 'token' }}
|
|
67
|
+
/>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Fork display
|
|
71
|
+
|
|
72
|
+
```astro
|
|
73
|
+
<!-- side-by-side -->
|
|
74
|
+
<AdaptAutomation
|
|
75
|
+
id="auto-123"
|
|
76
|
+
forkDisplayMode="side-by-side"
|
|
77
|
+
sideBySideSplit={60}
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
<!-- dialog -->
|
|
81
|
+
<AdaptAutomation
|
|
82
|
+
id="auto-123"
|
|
83
|
+
forkDisplayMode="dialog"
|
|
84
|
+
dialogBackdropClose
|
|
85
|
+
/>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Props
|
|
89
|
+
|
|
90
|
+
| Prop | Type |
|
|
91
|
+
|------|------|
|
|
92
|
+
| `id` | `string` (required) |
|
|
93
|
+
| `sessionToken` | `string` |
|
|
94
|
+
| `authToken` | `string` |
|
|
95
|
+
| `inheritToken` | `string` |
|
|
96
|
+
| `inheritFrom` | `{ hash: string } \| { param: string }` |
|
|
97
|
+
| `forkDisplayMode` | `'side-by-side' \| 'dialog'` |
|
|
98
|
+
| `sideBySideSplit` | `number` (0-100) |
|
|
99
|
+
| `dialogBackdropClose` | `boolean` |
|
|
100
|
+
| `class` | `string` |
|
|
101
|
+
| `style` | `string` |
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
ISC © mochabug AB
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mochabug/adapt-astro",
|
|
3
|
+
"version": "1.0.0-rc1",
|
|
4
|
+
"description": "Astro component for Adapt automation platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.ts",
|
|
11
|
+
"import": "./src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"./AdaptAutomation.astro": "./src/AdaptAutomation.astro"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "echo 'Astro component distributes source - no build needed'",
|
|
20
|
+
"sample": "cd sample && npm install && npm run dev"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"adapt",
|
|
24
|
+
"automations",
|
|
25
|
+
"mochabug",
|
|
26
|
+
"astro"
|
|
27
|
+
],
|
|
28
|
+
"author": "mochabug AB",
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@mochabug/adapt-web": "^1.0.0-rc22"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { AdaptWebClientOptions } from "@mochabug/adapt-web";
|
|
3
|
+
|
|
4
|
+
export interface Props
|
|
5
|
+
extends Pick<
|
|
6
|
+
AdaptWebClientOptions,
|
|
7
|
+
| "id"
|
|
8
|
+
| "sessionToken"
|
|
9
|
+
| "authToken"
|
|
10
|
+
| "inheritToken"
|
|
11
|
+
| "inheritFrom"
|
|
12
|
+
| "forkDisplayMode"
|
|
13
|
+
| "sideBySideSplit"
|
|
14
|
+
| "dialogBackdropClose"
|
|
15
|
+
| "classNames"
|
|
16
|
+
> {
|
|
17
|
+
/** CSS class name for the container */
|
|
18
|
+
class?: string;
|
|
19
|
+
/** Inline styles for the container */
|
|
20
|
+
style?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
sessionToken,
|
|
26
|
+
authToken,
|
|
27
|
+
inheritToken,
|
|
28
|
+
inheritFrom,
|
|
29
|
+
forkDisplayMode = "side-by-side",
|
|
30
|
+
sideBySideSplit = 50,
|
|
31
|
+
dialogBackdropClose = false,
|
|
32
|
+
classNames,
|
|
33
|
+
class: className,
|
|
34
|
+
style,
|
|
35
|
+
} = Astro.props;
|
|
36
|
+
|
|
37
|
+
const containerId = `adapt-${Math.random().toString(36).slice(2, 11)}`;
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
<div
|
|
41
|
+
id={containerId}
|
|
42
|
+
class={className}
|
|
43
|
+
style={style}
|
|
44
|
+
data-adapt-id={id}
|
|
45
|
+
data-adapt-session-token={sessionToken}
|
|
46
|
+
data-adapt-auth-token={authToken}
|
|
47
|
+
data-adapt-inherit-token={inheritToken}
|
|
48
|
+
data-adapt-inherit-from={inheritFrom ? JSON.stringify(inheritFrom) : undefined}
|
|
49
|
+
data-adapt-fork-display-mode={forkDisplayMode}
|
|
50
|
+
data-adapt-side-by-side-split={sideBySideSplit}
|
|
51
|
+
data-adapt-dialog-backdrop-close={dialogBackdropClose}
|
|
52
|
+
data-adapt-class-names={classNames ? JSON.stringify(classNames) : undefined}
|
|
53
|
+
></div>
|
|
54
|
+
|
|
55
|
+
<script>
|
|
56
|
+
import { AdaptWebClient } from "@mochabug/adapt-web";
|
|
57
|
+
|
|
58
|
+
function initAdaptAutomation(container: HTMLElement) {
|
|
59
|
+
const id = container.dataset.adaptId;
|
|
60
|
+
if (!id) return;
|
|
61
|
+
|
|
62
|
+
const inheritFromStr = container.dataset.adaptInheritFrom;
|
|
63
|
+
const classNamesStr = container.dataset.adaptClassNames;
|
|
64
|
+
|
|
65
|
+
const client = new AdaptWebClient({
|
|
66
|
+
container: container.id,
|
|
67
|
+
id,
|
|
68
|
+
sessionToken: container.dataset.adaptSessionToken,
|
|
69
|
+
authToken: container.dataset.adaptAuthToken,
|
|
70
|
+
inheritToken: container.dataset.adaptInheritToken,
|
|
71
|
+
inheritFrom: inheritFromStr ? JSON.parse(inheritFromStr) : undefined,
|
|
72
|
+
forkDisplayMode: container.dataset.adaptForkDisplayMode as "side-by-side" | "dialog",
|
|
73
|
+
sideBySideSplit: Number(container.dataset.adaptSideBySideSplit) || 50,
|
|
74
|
+
dialogBackdropClose: container.dataset.adaptDialogBackdropClose === "true",
|
|
75
|
+
classNames: classNamesStr ? JSON.parse(classNamesStr) : undefined,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Store reference for cleanup
|
|
79
|
+
(container as any).__adaptClient = client;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function cleanupAdaptAutomation(container: HTMLElement) {
|
|
83
|
+
const client = (container as any).__adaptClient;
|
|
84
|
+
if (client) {
|
|
85
|
+
client.destroy();
|
|
86
|
+
delete (container as any).__adaptClient;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Initialize all Adapt containers on page load
|
|
91
|
+
function initAll() {
|
|
92
|
+
document.querySelectorAll<HTMLElement>("[data-adapt-id]").forEach((container) => {
|
|
93
|
+
if (!(container as any).__adaptClient) {
|
|
94
|
+
initAdaptAutomation(container);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Initial load
|
|
100
|
+
initAll();
|
|
101
|
+
|
|
102
|
+
// Handle Astro View Transitions (page navigation without full reload)
|
|
103
|
+
document.addEventListener("astro:page-load", initAll);
|
|
104
|
+
|
|
105
|
+
// Cleanup before page swap (View Transitions)
|
|
106
|
+
document.addEventListener("astro:before-swap", () => {
|
|
107
|
+
document.querySelectorAll<HTMLElement>("[data-adapt-id]").forEach(cleanupAdaptAutomation);
|
|
108
|
+
});
|
|
109
|
+
</script>
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Import the component directly from the .astro file
|
|
2
|
+
// Usage: import { AdaptAutomation } from '@mochabug/adapt-astro';
|
|
3
|
+
// or: import AdaptAutomation from '@mochabug/adapt-astro/AdaptAutomation.astro';
|
|
4
|
+
|
|
5
|
+
// Re-export types for convenience
|
|
6
|
+
export type { Output, StatusJson } from "@mochabug/adapt-core";
|
|
7
|
+
export type { AdaptWebClientOptions } from "@mochabug/adapt-web";
|