@ingridab/sdk 0.1.0-alpha.1 → 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/README.md +108 -0
- package/dist/LICENSES.md +37 -0
- package/dist/index.d.ts +610 -514
- package/dist/index.js +2514 -2470
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -1 +1,109 @@
|
|
|
1
1
|
# @ingridab/sdk
|
|
2
|
+
|
|
3
|
+
Vanilla JS SDK for embedding Ingrid Experience Kit compounds into any web
|
|
4
|
+
application. Framework-agnostic; for a React-flavoured binding see
|
|
5
|
+
[`@ingridab/sdk-react`](../sdk-react).
|
|
6
|
+
|
|
7
|
+
The initial release ships the `address` molecule; additional molecules will
|
|
8
|
+
be made available in future releases.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pnpm add @ingridab/sdk
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Initialize the SDK with your credentials and the molecules to render, then
|
|
19
|
+
mount the returned compound into a container element in the DOM.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import initIngrid, { createAddressMolecule } from '@ingridab/sdk';
|
|
23
|
+
|
|
24
|
+
const ingrid = await initIngrid({
|
|
25
|
+
token: 'your-auth-token',
|
|
26
|
+
siteId: 'your-site-id',
|
|
27
|
+
locale: 'en-US',
|
|
28
|
+
molecules: [createAddressMolecule({ mode: 'addressForm' })],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
await ingrid.compound.mount('#ingrid-container');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Listening to events
|
|
35
|
+
|
|
36
|
+
The compound exposes a catch-all `on(event, callback)` API. Subscriptions
|
|
37
|
+
return an unsubscribe function.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const unsubscribe = ingrid.compound.on('addressSubmit', ({ payload }) => {
|
|
41
|
+
console.log('submitted address', payload);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
ingrid.compound.on('ready', () => {
|
|
45
|
+
console.log('compound mounted and interactive');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
unsubscribe();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Runtime updates
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// Change locale across the mounted experience
|
|
55
|
+
ingrid.setLocale('sv-SE');
|
|
56
|
+
|
|
57
|
+
// Update theme tokens without remounting
|
|
58
|
+
ingrid.compound.update({
|
|
59
|
+
styles: {
|
|
60
|
+
'--ingrid-color-primary': '#0050ff',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Tear it all down
|
|
65
|
+
ingrid.compound.unmount();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Data providers
|
|
69
|
+
|
|
70
|
+
The SDK ships with default data providers that talk to Ingrid's hosted API.
|
|
71
|
+
You can override individual services at init time - useful when you want to
|
|
72
|
+
route requests through your own backend, inject auth, mock data in tests, or
|
|
73
|
+
extend the default behaviour with logging.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import initIngrid, { withDefaultProvider } from '@ingridab/sdk';
|
|
77
|
+
|
|
78
|
+
const ingrid = await initIngrid({
|
|
79
|
+
token,
|
|
80
|
+
siteId,
|
|
81
|
+
locale: 'en-US',
|
|
82
|
+
molecules: [createAddressMolecule({ mode: 'addressForm' })],
|
|
83
|
+
dataProviders: {
|
|
84
|
+
services: {
|
|
85
|
+
address: {
|
|
86
|
+
// Replace the default implementation entirely.
|
|
87
|
+
listSuggestions: async args => {
|
|
88
|
+
const res = await fetch('/api/address/suggestions', {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
body: JSON.stringify(args.params),
|
|
91
|
+
});
|
|
92
|
+
return res.json();
|
|
93
|
+
},
|
|
94
|
+
// Or wrap the default with `withDefaultProvider` to extend it.
|
|
95
|
+
validateAddress: withDefaultProvider(defaultFn => async args => {
|
|
96
|
+
console.log('validating address', args.params);
|
|
97
|
+
return defaultFn(args);
|
|
98
|
+
}),
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The request/response shapes used by the providers mirror Ingrid's public REST
|
|
106
|
+
API. Refer to the OpenAPI specification for endpoint contracts, payload
|
|
107
|
+
fields, and error responses:
|
|
108
|
+
|
|
109
|
+
https://docs.ingrid.com/developer-resources/ingrid-api/openapi
|
package/dist/LICENSES.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Licenses
|
|
2
|
+
|
|
3
|
+
The app bundles dependencies which contain the following licenses:
|
|
4
|
+
|
|
5
|
+
## axios - 1.16.1 (MIT)
|
|
6
|
+
|
|
7
|
+
# Copyright (c) 2014-present Matt Zabriskie & Collaborators
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
|
+
|
|
15
|
+
## i18next - 25.5.2 (MIT)
|
|
16
|
+
|
|
17
|
+
The MIT License (MIT)
|
|
18
|
+
|
|
19
|
+
Copyright (c) 2025 i18next
|
|
20
|
+
|
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
in the Software without restriction, including without limitation the rights
|
|
24
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
furnished to do so, subject to the following conditions:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
SOFTWARE.
|