@ingridab/sdk 0.1.0-alpha.1 → 0.2.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 CHANGED
@@ -1 +1,118 @@
1
1
  # @ingridab/sdk
2
+
3
+ Vanilla JS SDK for embedding Ingrid Experience Kit compounds into any web
4
+ application.
5
+
6
+ The initial release ships the `address` molecule; additional molecules will
7
+ be made available in future releases.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ pnpm add @ingridab/sdk
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Initialize the SDK with your credentials and the molecules to render, then
18
+ mount the returned compound into a container element in the DOM.
19
+
20
+ ```ts
21
+ import ingrid, { createAddressMolecule } from '@ingridab/sdk';
22
+
23
+ const instance = await ingrid.init({
24
+ token: 'your-auth-token',
25
+ siteId: 'your-site-id',
26
+ locale: 'en-US',
27
+ countryCode: 'US',
28
+ currency: 'USD',
29
+ molecules: [createAddressMolecule({ mode: 'addressForm' })],
30
+ });
31
+
32
+ await instance.compound.mount('#ingrid-container');
33
+ ```
34
+
35
+ ### Auth
36
+
37
+ `refreshToken` is optional. Use it with short-lived Ingrid API tokens, which are
38
+ preferred. The callback should call your backend and return a fresh token issued by the
39
+ integrator with its expiration timestamp: `{ accessToken, expiresAt }`.
40
+
41
+ ### Listening to events
42
+
43
+ The compound exposes a catch-all `on(event, callback)` API. Subscriptions
44
+ return an unsubscribe function.
45
+
46
+ ```ts
47
+ const unsubscribe = instance.compound.on('addressSubmit', ({ payload }) => {
48
+ console.log('submitted address', payload);
49
+ });
50
+
51
+ instance.compound.on('ready', () => {
52
+ console.log('compound mounted and interactive');
53
+ });
54
+
55
+ unsubscribe();
56
+ ```
57
+
58
+ ### Runtime updates
59
+
60
+ ```ts
61
+ // Change locale across the mounted experience
62
+ instance.setLocale('sv-SE');
63
+
64
+ // Update theme tokens without remounting
65
+ instance.compound.update({
66
+ styles: {
67
+ '--color-bg-primary': '#0050ff',
68
+ },
69
+ });
70
+
71
+ // Tear it all down
72
+ instance.compound.unmount();
73
+ ```
74
+
75
+ ## Data providers
76
+
77
+ The SDK ships with default data providers that talk to Ingrid's hosted API.
78
+ You can override individual services at init time - useful when you want to
79
+ route requests through your own backend, inject auth, mock data in tests, or
80
+ extend the default behaviour with logging.
81
+
82
+ ```ts
83
+ import ingrid, { createAddressMolecule, withDefaultProvider } from '@ingridab/sdk';
84
+
85
+ const instance = await ingrid.init({
86
+ token,
87
+ siteId,
88
+ locale: 'en-US',
89
+ countryCode: 'US',
90
+ currency: 'USD',
91
+ molecules: [createAddressMolecule({ mode: 'addressForm' })],
92
+ dataProviders: {
93
+ services: {
94
+ address: {
95
+ // Replace the default implementation entirely.
96
+ listSuggestions: async args => {
97
+ const res = await fetch('/api/address/suggestions', {
98
+ method: 'POST',
99
+ body: JSON.stringify(args.params),
100
+ });
101
+ return res.json();
102
+ },
103
+ // Or wrap the default with `withDefaultProvider` to extend it.
104
+ validateAddress: withDefaultProvider(defaultFn => async args => {
105
+ console.log('validating address', args.params);
106
+ return defaultFn(args);
107
+ }),
108
+ },
109
+ },
110
+ },
111
+ });
112
+ ```
113
+
114
+ The request/response shapes used by the providers mirror Ingrid's public REST
115
+ API. Refer to the OpenAPI specification for endpoint contracts, payload
116
+ fields, and error responses:
117
+
118
+ https://docs.ingrid.com/developer-resources/ingrid-api/openapi
@@ -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.