@magiclabs.ai/magicbook-client 0.6.6 → 0.6.8-canary
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/example/.env.example +1 -0
- package/example/index.html +13 -0
- package/example/package.json +35 -0
- package/example/pnpm-lock.yaml +3403 -0
- package/example/postcss.config.js +6 -0
- package/example/public/logo.png +0 -0
- package/example/public/vite.svg +1 -0
- package/example/src/App.tsx +172 -0
- package/example/src/components/layout.tsx +36 -0
- package/example/src/index.css +3 -0
- package/example/src/main.tsx +10 -0
- package/example/src/vite-env.d.ts +1 -0
- package/example/tailwind.config.js +12 -0
- package/example/tsconfig.json +21 -0
- package/example/tsconfig.node.json +9 -0
- package/example/vite.config.ts +7 -0
- package/package.json +5 -5
- package/src/index.ts +4 -0
- package/tsconfig.json +13 -0
- package/tsup.config.ts +20 -0
- package/index.cjs +0 -4853
- package/index.cjs.map +0 -1
- package/index.d.cts +0 -1751
- package/index.d.ts +0 -1751
- package/index.js +0 -4815
- package/index.js.map +0 -1
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DesignRequest,
|
|
3
|
+
DesignRequestEvent,
|
|
4
|
+
DesignRequestEventDetail,
|
|
5
|
+
Image,
|
|
6
|
+
MagicBookClient
|
|
7
|
+
} from '@magiclabs.ai/magicbook-client'
|
|
8
|
+
import {Layout} from './components/layout'
|
|
9
|
+
import {faker} from '@faker-js/faker'
|
|
10
|
+
import {useEffect, useState} from 'react'
|
|
11
|
+
|
|
12
|
+
function App() {
|
|
13
|
+
const client = new MagicBookClient(import.meta.env.VITE_MB_CLIENT_API_KEY as string)
|
|
14
|
+
const [isCreatingDesignRequest, setIsCreatingDesignRequest] = useState<boolean>(false)
|
|
15
|
+
const [designRequestEventDetail, setDesignRequestEventDetail] = useState<DesignRequestEventDetail | null>()
|
|
16
|
+
const [currentDesignRequest, setDesignRequest] = useState<DesignRequest | null>()
|
|
17
|
+
|
|
18
|
+
function handleDesignRequestUpdated(designRequestEvent: DesignRequestEvent) {
|
|
19
|
+
console.log('MagicBook.designRequestUpdated', designRequestEvent.detail)
|
|
20
|
+
setDesignRequestEventDetail(designRequestEvent.detail)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function addMagicBookEventListener() {
|
|
24
|
+
window.addEventListener('MagicBook.designRequestUpdated', handleDesignRequestUpdated as EventListener)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function removeMagicBookEventListener() {
|
|
28
|
+
window.removeEventListener('MagicBook.designRequestUpdated', handleDesignRequestUpdated as EventListener)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (designRequestEventDetail?.slug === 'ready' && currentDesignRequest) {
|
|
33
|
+
currentDesignRequest.getJSON().then((res) => {
|
|
34
|
+
console.log('designRequest.getJSON:', res)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
return () => {
|
|
38
|
+
removeMagicBookEventListener()
|
|
39
|
+
}
|
|
40
|
+
}, [designRequestEventDetail])
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (isCreatingDesignRequest) {
|
|
44
|
+
addMagicBookEventListener()
|
|
45
|
+
} else {
|
|
46
|
+
setDesignRequestEventDetail(null)
|
|
47
|
+
removeMagicBookEventListener()
|
|
48
|
+
}
|
|
49
|
+
return () => {
|
|
50
|
+
removeMagicBookEventListener()
|
|
51
|
+
}
|
|
52
|
+
}, [isCreatingDesignRequest])
|
|
53
|
+
|
|
54
|
+
async function createDesignRequest() {
|
|
55
|
+
setIsCreatingDesignRequest(true)
|
|
56
|
+
const designRequest = await client.createDesignRequest({
|
|
57
|
+
occasion: 'default',
|
|
58
|
+
style: 5144,
|
|
59
|
+
bookSize: '10x10',
|
|
60
|
+
coverType: 'hc',
|
|
61
|
+
pageType: 'sp'
|
|
62
|
+
})
|
|
63
|
+
designRequest.title = 'My Book'
|
|
64
|
+
console.log('designRequest:', designRequest)
|
|
65
|
+
const imagesLength = 25
|
|
66
|
+
await Promise.all(Array.from(Array(imagesLength).keys()).map(async () => {
|
|
67
|
+
const width = 1000
|
|
68
|
+
const height = faker.number.int({min: 200, max: 500})
|
|
69
|
+
const image: Image = {
|
|
70
|
+
handle: faker.string.uuid(),
|
|
71
|
+
url: faker.image.url({width, height}),
|
|
72
|
+
width,
|
|
73
|
+
height,
|
|
74
|
+
rotation: 0,
|
|
75
|
+
captureTime: faker.date.past().toISOString(),
|
|
76
|
+
cameraMake: '',
|
|
77
|
+
cameraModel: 'Sony A7R IV',
|
|
78
|
+
filename: faker.system.commonFileName('jpg')
|
|
79
|
+
}
|
|
80
|
+
await designRequest.images.add(image)
|
|
81
|
+
console.log('designRequest.images.add:', image)
|
|
82
|
+
}))
|
|
83
|
+
console.log('designRequest.images.length:', designRequest.images.length)
|
|
84
|
+
console.log('designRequest.getOptions:', await designRequest.getOptions())
|
|
85
|
+
console.log('designRequest.submit:', await designRequest.submit({
|
|
86
|
+
imageDensity: 'high',
|
|
87
|
+
embellishmentLevel: 'few',
|
|
88
|
+
textStickerLevel: 'none'
|
|
89
|
+
}))
|
|
90
|
+
console.log('designRequest.setGuid:', await designRequest.setGuid(faker.string.uuid()))
|
|
91
|
+
setDesignRequest(designRequest)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function cancelDesignRequest() {
|
|
95
|
+
if (currentDesignRequest) {
|
|
96
|
+
console.log('designRequest.cancel:', await currentDesignRequest.cancel())
|
|
97
|
+
}
|
|
98
|
+
// setDesignRequest(null)
|
|
99
|
+
// setIsCreatingDesignRequest(false)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<Layout>
|
|
104
|
+
<div className='flex justify-center h-8 mb-8'>
|
|
105
|
+
{designRequestEventDetail &&
|
|
106
|
+
<div className='relative w-auto px-3 py-1 text-sm leading-6 text-gray-600 rounded-full ring-1 \
|
|
107
|
+
ring-gray-900/10 hover:ring-gray-900/20'>
|
|
108
|
+
<span className='flex items-center justify-center space-x-2'>
|
|
109
|
+
<span className='font-semibold'>Design request</span>
|
|
110
|
+
<div className="w-px h-5 bg-gray-900/10" aria-hidden />
|
|
111
|
+
<span>{designRequestEventDetail.message}</span>
|
|
112
|
+
</span>
|
|
113
|
+
{designRequestEventDetail.slug !== 'ready' &&
|
|
114
|
+
<span className='absolute -right-1 -top-1'>
|
|
115
|
+
<span className='relative flex w-3 h-3'>
|
|
116
|
+
<span className='absolute inline-flex w-full h-full bg-indigo-400 rounded-full opacity-75 \
|
|
117
|
+
animate-ping'></span>
|
|
118
|
+
<span className='relative inline-flex w-3 h-3 bg-indigo-500 rounded-full'></span>
|
|
119
|
+
</span>
|
|
120
|
+
</span>
|
|
121
|
+
}
|
|
122
|
+
</div>
|
|
123
|
+
}
|
|
124
|
+
</div>
|
|
125
|
+
<div className='text-center'>
|
|
126
|
+
<h1 className='text-4xl font-bold tracking-tight text-gray-900 sm:text-6xl'>
|
|
127
|
+
MagicBook Client Example
|
|
128
|
+
</h1>
|
|
129
|
+
<p className='mt-6 text-lg leading-8 text-gray-600'>
|
|
130
|
+
This is an example of a MagicBook client. It is a simple HTML page that imports the magicbook-client module
|
|
131
|
+
and uses it to connect to the MagicBook server.
|
|
132
|
+
</p>
|
|
133
|
+
<div className='flex items-center justify-center mt-10 gap-x-6'>
|
|
134
|
+
<button
|
|
135
|
+
onClick={createDesignRequest}
|
|
136
|
+
disabled={isCreatingDesignRequest}
|
|
137
|
+
className='rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm
|
|
138
|
+
hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2
|
|
139
|
+
focus-visible:outline-indigo-600 disabled:opacity-50 disabled:cursor-not-allowed'
|
|
140
|
+
>
|
|
141
|
+
Create design request
|
|
142
|
+
</button>
|
|
143
|
+
<a
|
|
144
|
+
href='https://www.npmjs.com/package/@magiclabs.ai/magicbook-client'
|
|
145
|
+
target='_blank'
|
|
146
|
+
className='text-sm font-semibold leading-6 text-gray-900'>
|
|
147
|
+
Learn more <span aria-hidden='true'>→</span>
|
|
148
|
+
</a>
|
|
149
|
+
</div>
|
|
150
|
+
<div className='mt-2'>
|
|
151
|
+
{currentDesignRequest &&
|
|
152
|
+
<button
|
|
153
|
+
onClick={cancelDesignRequest}
|
|
154
|
+
className='rounded-md bg-red-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm
|
|
155
|
+
hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2
|
|
156
|
+
focus-visible:outline-red-600'
|
|
157
|
+
>
|
|
158
|
+
Cancel design request
|
|
159
|
+
</button>
|
|
160
|
+
}
|
|
161
|
+
</div>
|
|
162
|
+
<div className='fixed bottom-0 left-0 w-full backdrop-blur-sm'>
|
|
163
|
+
<p className='flex items-center justify-center m-4 font-mono text-xs leading-8 text-gray-600 rounded-full'>
|
|
164
|
+
💡 Open your browser's developer console to see the client in action.
|
|
165
|
+
</p>
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
</Layout>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export default App
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function Layout({children}: {children: React.ReactNode}) {
|
|
2
|
+
return (
|
|
3
|
+
<div className='bg-white'>
|
|
4
|
+
<div className='relative'>
|
|
5
|
+
<div
|
|
6
|
+
className='fixed inset-x-0 overflow-hidden -top-40 -z-10 transform-gpu blur-3xl sm:-top-80'
|
|
7
|
+
aria-hidden='true'
|
|
8
|
+
>
|
|
9
|
+
<div
|
|
10
|
+
className='relative left-[calc(50%-11rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 rotate-[30deg]
|
|
11
|
+
bg-gradient-to-tr from-[#ff80b5] to-[#9089fc] opacity-30 sm:left-[calc(50%-30rem)] sm:w-[72.1875rem]'
|
|
12
|
+
// eslint-disable-next-line max-len
|
|
13
|
+
style={{clipPath: 'polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)'}}
|
|
14
|
+
/>
|
|
15
|
+
</div>
|
|
16
|
+
<div className='absolute w-full px-6 pt-14 lg:px-8'>
|
|
17
|
+
<div className='max-w-2xl py-32 mx-auto sm:py-48 lg:py-56'>
|
|
18
|
+
{children}
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
<div
|
|
22
|
+
className='fixed inset-x-0 top-[calc(100%-13rem)] -z-10 transform-gpu overflow-hidden blur-3xl
|
|
23
|
+
sm:top-[calc(100%-30rem)]'
|
|
24
|
+
aria-hidden='true'
|
|
25
|
+
>
|
|
26
|
+
<div
|
|
27
|
+
className='relative left-[calc(50%+3rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 bg-gradient-to-tr
|
|
28
|
+
from-[#ff80b5] to-[#9089fc] opacity-30 sm:left-[calc(50%+36rem)] sm:w-[72.1875rem]'
|
|
29
|
+
// eslint-disable-next-line max-len
|
|
30
|
+
style={{clipPath: 'polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)'}}
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
6
|
+
"allowJs": false,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"esModuleInterop": false,
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"module": "ESNext",
|
|
13
|
+
"moduleResolution": "Node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"jsx": "react-jsx"
|
|
18
|
+
},
|
|
19
|
+
"include": ["src"],
|
|
20
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magiclabs.ai/magicbook-client",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8-canary",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "TypeScript package to create photo books with the Magicbook API.",
|
|
6
6
|
"repository": {
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"import": "./index.js",
|
|
14
|
-
"require": "./index.cjs"
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
"main": "./index.cjs",
|
|
18
|
-
"module": "./index.js",
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
19
|
"types": "./src/index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"dotenv": "^16.3.1",
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as dotenv from 'dotenv'
|
|
2
|
+
import {defineConfig} from 'tsup'
|
|
3
|
+
|
|
4
|
+
dotenv.config({path: '../../.env'})
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
clean: true,
|
|
8
|
+
dts: true,
|
|
9
|
+
entry: ['src/index.ts'],
|
|
10
|
+
format: ['esm', 'cjs'],
|
|
11
|
+
sourcemap: true,
|
|
12
|
+
env: {
|
|
13
|
+
API_HOST: process.env.API_HOST || '',
|
|
14
|
+
WEBSOCKET_HOST: process.env.WEBSOCKET_HOST || '',
|
|
15
|
+
DESIGN_REQUEST_TIMEOUT: process.env.DESIGN_REQUEST_TIMEOUT || ''
|
|
16
|
+
},
|
|
17
|
+
target: 'esnext',
|
|
18
|
+
outDir: 'dist'
|
|
19
|
+
})
|
|
20
|
+
|