@pro6pp/infer-core 0.0.2-beta.0 → 0.0.2-beta.10

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/dist/index.js CHANGED
@@ -1,228 +1,180 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
-
22
- // src/index.ts
23
- var index_exports = {};
24
- __export(index_exports, {
25
- INITIAL_STATE: () => INITIAL_STATE,
26
- InferCore: () => InferCore
27
- });
28
- module.exports = __toCommonJS(index_exports);
29
-
30
- // src/core.ts
31
- var DEFAULTS = {
32
- API_URL: "https://api.pro6pp.nl/v2",
33
- LIMIT: 1e3,
34
- DEBOUNCE_MS: 300
35
- };
36
- var PATTERNS = {
37
- DIGITS_1_3: /^[0-9]{1,3}$/
38
- };
39
- var INITIAL_STATE = {
40
- query: "",
41
- stage: null,
42
- cities: [],
43
- streets: [],
44
- suggestions: [],
45
- isValid: false,
46
- isError: false,
47
- isLoading: false
48
- };
49
- var InferCore = class {
50
- constructor(config) {
51
- __publicField(this, "country");
52
- __publicField(this, "authKey");
53
- __publicField(this, "apiUrl");
54
- __publicField(this, "limit");
55
- __publicField(this, "fetcher");
56
- __publicField(this, "onStateChange");
57
- __publicField(this, "onSelect");
58
- __publicField(this, "state");
59
- __publicField(this, "abortController", null);
60
- __publicField(this, "debouncedFetch");
61
- this.country = config.country;
62
- this.authKey = config.authKey;
63
- this.apiUrl = config.apiUrl || DEFAULTS.API_URL;
64
- this.limit = config.limit || DEFAULTS.LIMIT;
65
- this.fetcher = config.fetcher || ((url, init) => fetch(url, init));
66
- this.onStateChange = config.onStateChange || (() => {
67
- });
68
- this.onSelect = config.onSelect || (() => {
69
- });
70
- this.state = { ...INITIAL_STATE };
71
- this.debouncedFetch = this.debounce(
72
- (val) => this.executeFetch(val),
73
- DEFAULTS.DEBOUNCE_MS
74
- );
75
- }
76
- handleInput(value) {
77
- this.updateState({
78
- query: value,
79
- isValid: false,
80
- isLoading: !!value.trim()
81
- });
82
- if (this.state.stage === "final") {
83
- this.onSelect(null);
84
- }
85
- this.debouncedFetch(value);
86
- }
87
- handleKeyDown(event) {
88
- const target = event.target;
89
- const val = target.value;
90
- if (event.key === " " && this.shouldAutoInsertComma(val)) {
91
- event.preventDefault();
92
- const next = `${val.trim()}, `;
93
- this.updateQueryAndFetch(next);
94
- }
1
+ var x=Object.defineProperty;var S=(a,t,e)=>t in a?x(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var l=(a,t,e)=>S(a,typeof t!="symbol"?t+"":t,e);var c={API_URL:"https://api.pro6pp.nl/v2",LIMIT:20,DEBOUNCE_MS:150,MIN_DEBOUNCE_MS:50,MAX_RETRIES:0},g={DIGITS_1_3:/^[0-9]{1,3}$/},f={query:"",stage:null,cities:[],streets:[],suggestions:[],isValid:!1,isError:!1,isLoading:!1,hasMore:!1,selectedSuggestionIndex:-1},m=class{constructor(t){l(this,"country");l(this,"authKey");l(this,"explicitApiUrl");l(this,"baseLimit");l(this,"currentLimit");l(this,"maxRetries");l(this,"fetcher");l(this,"onStateChange");l(this,"onSelect");l(this,"state");l(this,"abortController",null);l(this,"debouncedFetch");this.country=t.country,this.authKey=t.authKey,this.explicitApiUrl=t.apiUrl,this.baseLimit=t.limit||c.LIMIT,this.currentLimit=this.baseLimit;let e=t.maxRetries!==void 0?t.maxRetries:c.MAX_RETRIES;this.maxRetries=Math.max(0,Math.min(e,10)),this.fetcher=t.fetcher||((r,o)=>fetch(r,o)),this.onStateChange=t.onStateChange||(()=>{}),this.onSelect=t.onSelect||(()=>{}),this.state={...f};let i=t.debounceMs!==void 0?t.debounceMs:c.DEBOUNCE_MS,s=Math.max(i,c.MIN_DEBOUNCE_MS);this.debouncedFetch=this.debounce(r=>this.executeFetch(r),s)}handleInput(t){this.currentLimit=this.baseLimit;let e=this.state.stage==="final"&&t!==this.state.query;this.updateState({query:t,isValid:!1,isLoading:!!t.trim(),selectedSuggestionIndex:-1,hasMore:!1}),e&&this.onSelect(null),this.debouncedFetch(t)}loadMore(){this.state.isLoading||(this.currentLimit+=this.baseLimit,this.updateState({isLoading:!0}),this.executeFetch(this.state.query))}handleKeyDown(t){let e=t.target;if(!e)return;let i=this.state.cities.length+this.state.streets.length+this.state.suggestions.length;if(i>0){if(t.key==="ArrowDown"){t.preventDefault();let r=this.state.selectedSuggestionIndex+1;r>=i&&(r=0),this.updateState({selectedSuggestionIndex:r});return}if(t.key==="ArrowUp"){t.preventDefault();let r=this.state.selectedSuggestionIndex-1;r<0&&(r=i-1),this.updateState({selectedSuggestionIndex:r});return}if(t.key==="Enter"&&this.state.selectedSuggestionIndex>=0){t.preventDefault();let o=[...this.state.cities,...this.state.streets,...this.state.suggestions][this.state.selectedSuggestionIndex];o&&(this.selectItem(o),this.updateState({selectedSuggestionIndex:-1}));return}}let s=e.value;if(t.key===" "&&this.shouldAutoInsertComma(s)){t.preventDefault();let r=`${s.trim()}, `;this.updateQueryAndFetch(r)}}selectItem(t){this.debouncedFetch.cancel(),this.abortController&&this.abortController.abort();let e=typeof t=="string"?t:t.label,i=e;typeof t!="string"&&typeof t.value=="string"&&(i=t.value);let s=typeof t!="string"&&typeof t.value=="object"?t.value:void 0,r=!!s&&Object.keys(s).length>0;if(this.state.stage==="final"||r){let p=e;if(s&&Object.keys(s).length>0){let{street:u,street_number:n,city:d,addition:h}=s;if(u&&n&&d){let b=h?` ${h}`:"";p=`${u} ${n}${b}, ${d}`}}return this.finishSelection(p,s),!0}let o=typeof t!="string"?t.subtitle:null;return this.processSelection(i,o),!1}shouldAutoInsertComma(t){if(!t.includes(",")&&g.DIGITS_1_3.test(t.trim()))return!0;if(this.state.stage==="street_number"){let i=this.getCurrentFragment(t);return g.DIGITS_1_3.test(i)}return!1}finishSelection(t,e){this.updateState({query:t,suggestions:[],cities:[],streets:[],isValid:!0,stage:"final",hasMore:!1}),this.onSelect(e||t)}processSelection(t,e){let{stage:i,query:s}=this.state,r=s;if(e&&(i==="city"||i==="street"||i==="mixed")){if(i==="city")r=`${e}, ${t}, `;else{let n=this.getQueryPrefix(s);!n||!n.includes(e)?r=n?`${n} ${t}, ${e}, `:`${t}, ${e}, `:r=n?`${n} ${t}, `:`${t}, `}this.updateQueryAndFetch(r);return}if(i==="direct"||i==="addition"){this.finishSelection(t);return}!s.includes(",")&&(i==="city"||i==="street"||i==="street_number_first")?r=`${t}, `:(r=this.replaceLastSegment(s,t),i!=="street_number"&&(r+=", ")),this.updateQueryAndFetch(r)}executeFetch(t,e=0){let i=(t||"").toString();if(!i.trim()){this.abortController?.abort(),this.resetState();return}e===0&&(this.updateState({isError:!1}),this.abortController&&this.abortController.abort(),this.abortController=new AbortController);let s=this.abortController?.signal,r=this.explicitApiUrl?this.explicitApiUrl:`${c.API_URL}/infer/${this.country.toLowerCase()}`,o=new URLSearchParams({country:this.country.toLowerCase(),query:i,limit:this.currentLimit.toString()});this.authKey&&o.set("authKey",this.authKey);let p=r.includes("?")?"&":"?",u=`${r}${p}${o.toString()}`;this.fetcher(u,{signal:s}).then(n=>{if(!n.ok){if(e<this.maxRetries&&(n.status>=500||n.status===429))return this.retry(t,e,s);throw new Error("Network error")}return n.json()}).then(n=>{n&&this.mapResponseToState(n)}).catch(n=>{if(n.name!=="AbortError"){if(e<this.maxRetries)return this.retry(t,e,s);this.updateState({isError:!0,isLoading:!1})}})}retry(t,e,i){if(i?.aborted)return;let s=Math.pow(2,e)*200;setTimeout(()=>{i?.aborted||this.executeFetch(t,e+1)},s)}mapResponseToState(t){let e={stage:t.stage,isLoading:!1},i=t.suggestions||[],s=[],r=new Set;for(let p of i){let u=`${p.label}|${p.subtitle||""}|${JSON.stringify(p.value||{})}`;r.has(u)||(r.add(u),s.push(p))}let o=s.length+(t.cities?.length||0)+(t.streets?.length||0);e.hasMore=o>=this.currentLimit,t.stage==="mixed"?(e.cities=t.cities||[],e.streets=t.streets||[],e.suggestions=[]):(e.suggestions=s,e.cities=[],e.streets=[]),e.isValid=t.stage==="final",this.updateState(e),e.isValid&&s.length===1&&this.selectItem(s[0])}updateQueryAndFetch(t){this.updateState({query:t,suggestions:[],cities:[],streets:[]}),this.updateState({isLoading:!0,isValid:!1,hasMore:!1}),this.debouncedFetch(t)}replaceLastSegment(t,e){let i=t.lastIndexOf(",");return i===-1?e:`${t.slice(0,i+1)} ${e}`.trim()}getQueryPrefix(t){let e=t.lastIndexOf(",");return e===-1?"":t.slice(0,e+1).trimEnd()}getCurrentFragment(t){return(t.split(",").slice(-1)[0]??"").trim()}resetState(){this.updateState({...f,query:this.state.query})}updateState(t){this.state={...this.state,...t},this.onStateChange(this.state)}debounce(t,e){let i,s=(...r)=>{i&&clearTimeout(i),i=setTimeout(()=>t.apply(this,r),e)};return s.cancel=()=>{i&&(clearTimeout(i),i=void 0)},s}};function T(a,t){if(!t||!a)return[{text:a,match:!1}];let e=[],i=a.toLowerCase(),s=t.toLowerCase(),r=0,o=0;for(let n=0;n<a.length;n++){if(!(r<t.length&&i[n]===s[r]))continue;n>o&&e.push({text:a.slice(o,n),match:!1}),e.push({text:a[n],match:!0}),r++,o=n+1}return o<a.length&&e.push({text:a.slice(o),match:!1}),r===t.length?e:[{text:a,match:!1}]}var y=`
2
+ .pro6pp-wrapper {
3
+ position: relative;
4
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
5
+ box-sizing: border-box;
6
+ width: 100%;
7
+ -webkit-tap-highlight-color: transparent;
8
+ }
9
+ .pro6pp-wrapper * {
10
+ box-sizing: border-box;
11
+ }
12
+ .pro6pp-input {
13
+ width: 100%;
14
+ padding: 12px 14px;
15
+ padding-right: 48px;
16
+ border: 1px solid #e0e0e0;
17
+ border-radius: 8px;
18
+ font-size: 16px;
19
+ line-height: 1.5;
20
+ appearance: none;
21
+ transition: border-color 0.2s, box-shadow 0.2s;
22
+ }
23
+ .pro6pp-input:focus {
24
+ outline: none;
25
+ border-color: #3b82f6;
26
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
95
27
  }
96
- selectItem(item) {
97
- const label = typeof item === "string" ? item : item.label;
98
- const value = typeof item !== "string" ? item.value : void 0;
99
- const subtitle = typeof item !== "string" ? item.subtitle : null;
100
- if (this.state.stage === "final") {
101
- this.finishSelection(label, value);
102
- return;
103
- }
104
- this.processSelection(label, subtitle);
105
- }
106
- shouldAutoInsertComma(currentVal) {
107
- const isStartOfSegmentAndNumeric = !currentVal.includes(",") && PATTERNS.DIGITS_1_3.test(currentVal.trim());
108
- if (isStartOfSegmentAndNumeric) return true;
109
- if (this.state.stage === "house_number") {
110
- const currentFragment = this.getCurrentFragment(currentVal);
111
- return PATTERNS.DIGITS_1_3.test(currentFragment);
112
- }
113
- return false;
114
- }
115
- finishSelection(label, value) {
116
- this.updateState({ query: label, suggestions: [], cities: [], streets: [], isValid: true });
117
- this.onSelect(value || label);
118
- }
119
- processSelection(label, subtitle) {
120
- const { stage, query } = this.state;
121
- let nextQuery = query;
122
- const isContextualSelection = subtitle && (stage === "city" || stage === "street" || stage === "mixed");
123
- if (isContextualSelection) {
124
- if (stage === "city") {
125
- nextQuery = `${subtitle}, ${label}, `;
126
- } else {
127
- const prefix = this.getQueryPrefix(query);
128
- nextQuery = prefix ? `${prefix} ${label}, ${subtitle}, ` : `${label}, ${subtitle}, `;
129
- }
130
- this.updateQueryAndFetch(nextQuery);
131
- return;
132
- }
133
- if (stage === "direct" || stage === "addition") {
134
- this.finishSelection(label);
135
- this.handleInput(label);
136
- return;
137
- }
138
- const hasComma = query.includes(",");
139
- const isFirstSegment = !hasComma && (stage === "city" || stage === "street" || stage === "house_number_first");
140
- if (isFirstSegment) {
141
- nextQuery = `${label}, `;
142
- } else {
143
- nextQuery = this.replaceLastSegment(query, label);
144
- if (stage !== "house_number") {
145
- nextQuery += ", ";
146
- }
28
+
29
+ .pro6pp-input-addons {
30
+ position: absolute;
31
+ right: 4px;
32
+ top: 0;
33
+ bottom: 0;
34
+ display: flex;
35
+ align-items: center;
36
+ pointer-events: none;
37
+ }
38
+ .pro6pp-input-addons > * {
39
+ pointer-events: auto;
40
+ }
41
+
42
+ .pro6pp-clear-button {
43
+ background: none;
44
+ border: none;
45
+ width: 40px;
46
+ height: 40px;
47
+ cursor: pointer;
48
+ color: #a3a3a3;
49
+ display: flex;
50
+ align-items: center;
51
+ justify-content: center;
52
+ border-radius: 50%;
53
+ transition: color 0.2s, background-color 0.2s;
54
+ touch-action: manipulation;
55
+ }
56
+
57
+ @media (hover: hover) {
58
+ .pro6pp-clear-button:hover {
59
+ color: #1f2937;
60
+ background-color: #f3f4f6;
147
61
  }
148
- this.updateQueryAndFetch(nextQuery);
149
- }
150
- executeFetch(val) {
151
- const text = (val || "").toString();
152
- if (!text.trim()) {
153
- this.abortController?.abort();
154
- this.resetState();
155
- return;
62
+ }
63
+
64
+ .pro6pp-clear-button:active {
65
+ background-color: #f3f4f6;
66
+ }
67
+
68
+ .pro6pp-loader {
69
+ width: 20px;
70
+ height: 20px;
71
+ margin: 0 8px;
72
+ border: 2px solid #e0e0e0;
73
+ border-top-color: #6b7280;
74
+ border-radius: 50%;
75
+ animation: pro6pp-spin 0.6s linear infinite;
76
+ flex-shrink: 0;
77
+ }
78
+
79
+ .pro6pp-dropdown {
80
+ position: absolute;
81
+ top: 100%;
82
+ left: 0;
83
+ right: 0;
84
+ margin-top: 4px;
85
+ background: #ffffff;
86
+ border: 1px solid #e5e7eb;
87
+ border-radius: 6px;
88
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
89
+ z-index: 9999;
90
+ padding: 0;
91
+ max-height: 260px;
92
+ overflow-y: auto;
93
+ display: flex;
94
+ flex-direction: column;
95
+ }
96
+
97
+ @media (max-height: 500px) {
98
+ .pro6pp-dropdown {
99
+ max-height: 140px;
156
100
  }
157
- this.updateState({ isError: false });
158
- if (this.abortController) this.abortController.abort();
159
- this.abortController = new AbortController();
160
- const url = new URL(`${this.apiUrl}/infer/${this.country.toLowerCase()}`);
161
- const params = {
162
- authKey: this.authKey,
163
- query: text,
164
- limit: this.limit.toString()
165
- };
166
- url.search = new URLSearchParams(params).toString();
167
- this.fetcher(url.toString(), { signal: this.abortController.signal }).then((res) => {
168
- if (!res.ok) throw new Error("Network error");
169
- return res.json();
170
- }).then((data) => this.mapResponseToState(data)).catch((e) => {
171
- if (e.name !== "AbortError") {
172
- this.updateState({ isError: true, isLoading: false });
173
- }
174
- });
175
- }
176
- mapResponseToState(data) {
177
- const newState = {
178
- stage: data.stage,
179
- isLoading: false
180
- };
181
- if (data.stage === "mixed") {
182
- newState.cities = data.cities || [];
183
- newState.streets = data.streets || [];
184
- newState.suggestions = [];
185
- } else {
186
- newState.suggestions = data.suggestions || [];
187
- newState.cities = [];
188
- newState.streets = [];
101
+ }
102
+
103
+ .pro6pp-list {
104
+ list-style: none;
105
+ margin: 0;
106
+ padding: 0;
107
+ width: 100%;
108
+ }
109
+
110
+ .pro6pp-item {
111
+ padding: 12px 14px;
112
+ cursor: pointer;
113
+ display: flex;
114
+ align-items: center;
115
+ font-size: 14px;
116
+ color: #374151;
117
+ border-bottom: 1px solid #f3f4f6;
118
+ transition: background-color 0.1s;
119
+ flex-shrink: 0;
120
+ }
121
+
122
+ .pro6pp-item:last-child {
123
+ border-bottom: none;
124
+ }
125
+
126
+ @media (hover: hover) {
127
+ .pro6pp-item:hover, .pro6pp-item--active {
128
+ background-color: #f9fafb;
189
129
  }
190
- newState.isValid = data.stage === "final";
191
- this.updateState(newState);
192
- }
193
- updateQueryAndFetch(nextQuery) {
194
- this.updateState({ query: nextQuery, suggestions: [], cities: [], streets: [] });
195
- this.handleInput(nextQuery);
196
- }
197
- replaceLastSegment(fullText, newSegment) {
198
- const lastCommaIndex = fullText.lastIndexOf(",");
199
- if (lastCommaIndex === -1) return newSegment;
200
- return `${fullText.slice(0, lastCommaIndex + 1)} ${newSegment}`.trim();
201
- }
202
- getQueryPrefix(q) {
203
- const lastComma = q.lastIndexOf(",");
204
- return lastComma === -1 ? "" : q.slice(0, lastComma + 1).trimEnd();
205
- }
206
- getCurrentFragment(q) {
207
- return (q.split(",").slice(-1)[0] ?? "").trim();
208
- }
209
- resetState() {
210
- this.updateState({ ...INITIAL_STATE, query: this.state.query });
211
- }
212
- updateState(updates) {
213
- this.state = { ...this.state, ...updates };
214
- this.onStateChange(this.state);
215
- }
216
- debounce(func, wait) {
217
- let timeout;
218
- return (...args) => {
219
- if (timeout) clearTimeout(timeout);
220
- timeout = setTimeout(() => func.apply(this, args), wait);
221
- };
222
- }
223
- };
224
- // Annotate the CommonJS export names for ESM import in node:
225
- 0 && (module.exports = {
226
- INITIAL_STATE,
227
- InferCore
228
- });
130
+ }
131
+
132
+ .pro6pp-item:active {
133
+ background-color: #f3f4f6;
134
+ }
135
+
136
+ .pro6pp-item__label {
137
+ font-weight: 500;
138
+ flex-shrink: 0;
139
+ }
140
+ .pro6pp-item__subtitle {
141
+ font-size: 14px;
142
+ color: #6b7280;
143
+ flex-grow: 1;
144
+ }
145
+ .pro6pp-item__chevron {
146
+ color: #d1d5db;
147
+ display: flex;
148
+ align-items: center;
149
+ margin-left: auto;
150
+ }
151
+
152
+ .pro6pp-no-results {
153
+ padding: 24px 16px;
154
+ color: #6b7280;
155
+ font-size: 15px;
156
+ text-align: center;
157
+ }
158
+
159
+ .pro6pp-load-more {
160
+ width: 100%;
161
+ padding: 14px;
162
+ background: #f9fafb;
163
+ border: none;
164
+ border-top: 1px solid #e0e0e0;
165
+ color: #3b82f6;
166
+ font-size: 14px;
167
+ font-weight: 600;
168
+ cursor: pointer;
169
+ flex-shrink: 0;
170
+ touch-action: manipulation;
171
+ }
172
+
173
+ .pro6pp-load-more:active {
174
+ background-color: #f3f4f6;
175
+ }
176
+
177
+ @keyframes pro6pp-spin {
178
+ to { transform: rotate(360deg); }
179
+ }
180
+ `;export{y as DEFAULT_STYLES,f as INITIAL_STATE,m as InferCore,T as getHighlightSegments};
package/package.json CHANGED
@@ -1,14 +1,39 @@
1
1
  {
2
2
  "name": "@pro6pp/infer-core",
3
- "version": "0.0.2-beta.0",
4
- "main": "./dist/index.js",
5
- "module": "./dist/index.mjs",
3
+ "type": "module",
4
+ "description": "Core logic and client for the Pro6PP Infer API.",
5
+ "homepage": "https://github.com/pro6pp/infer-sdk/tree/main/packages/core",
6
+ "keywords": [
7
+ "pro6pp",
8
+ "infer-api",
9
+ "sdk",
10
+ "core",
11
+ "headless",
12
+ "address",
13
+ "autocomplete",
14
+ "validation",
15
+ "postal-code",
16
+ "netherlands",
17
+ "germany",
18
+ "api-client",
19
+ "typescript"
20
+ ],
21
+ "bugs": {
22
+ "url": "https://github.com/pro6pp/infer-sdk/issues"
23
+ },
24
+ "sideEffects": false,
25
+ "version": "0.0.2-beta.10",
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
6
28
  "types": "./dist/index.d.ts",
29
+ "unpkg": "./dist/index.global.js",
30
+ "jsdelivr": "./dist/index.global.js",
7
31
  "exports": {
8
32
  ".": {
9
33
  "types": "./dist/index.d.ts",
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.js"
34
+ "script": "./dist/index.global.js",
35
+ "import": "./dist/index.js",
36
+ "require": "./dist/index.cjs"
12
37
  }
13
38
  },
14
39
  "files": [
@@ -16,9 +41,11 @@
16
41
  "README.md"
17
42
  ],
18
43
  "scripts": {
19
- "build": "tsup src/index.ts --format cjs,esm --dts",
20
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
21
- "type-check": "tsc --noEmit"
44
+ "build": "tsup",
45
+ "dev": "tsup --watch",
46
+ "type-check": "tsc --noEmit",
47
+ "test": "vitest",
48
+ "test:coverage": "vitest run --coverage"
22
49
  },
23
50
  "devDependencies": {
24
51
  "tsup": "^8.0.0",
@@ -30,6 +57,7 @@
30
57
  "license": "MIT",
31
58
  "repository": {
32
59
  "type": "git",
33
- "url": "https://gitlab.d-centralize.nl/dc/pro6pp/pro6pp-infer-sdk"
60
+ "url": "git+https://github.com/pro6pp/infer-sdk.git",
61
+ "directory": "packages/core"
34
62
  }
35
63
  }
package/dist/index.d.mts DELETED
@@ -1,130 +0,0 @@
1
- /**
2
- * Supported ISO 3166-1 alpha-2 country codes.
3
- */
4
- type CountryCode = 'NL' | 'DE';
5
- /**
6
- * The current step in the address inference process.
7
- */
8
- type Stage = 'empty' | 'mixed' | 'street' | 'city' | 'postcode' | 'house_number' | 'house_number_first' | 'addition' | 'direct' | 'final';
9
- /**
10
- * The standardized address object returned upon selection.
11
- */
12
- interface AddressValue {
13
- street: string;
14
- city: string;
15
- street_number?: string | number;
16
- house_number?: string | number;
17
- postcode?: string;
18
- postcode_full?: string;
19
- addition?: string;
20
- /** Allow for extra fields if API expands. */
21
- [key: string]: unknown;
22
- }
23
- /**
24
- * A single item in the dropdown list.
25
- */
26
- interface InferResult {
27
- /** The text to display in the UI (e.g. "Amsterdam"). */
28
- label: string;
29
- /** The actual address data. Only present if this result completes an address. */
30
- value?: AddressValue;
31
- /** Helper text. */
32
- subtitle?: string | null;
33
- /** Number of underlying results (optional). */
34
- count?: number | string;
35
- }
36
- /**
37
- * The complete state returned by the `useInfer` hook.
38
- */
39
- interface InferState {
40
- /** The current value of the input field. */
41
- query: string;
42
- /** The current inference stage. */
43
- stage: Stage | null;
44
- /** List of cities to display, specific to `mixed` mode. */
45
- cities: InferResult[];
46
- /** List of streets to display, specific to `mixed` mode. */
47
- streets: InferResult[];
48
- /** General suggestions to display. */
49
- suggestions: InferResult[];
50
- /** True if a full, valid address has been selected. */
51
- isValid: boolean;
52
- /** True if the last network request failed. */
53
- isError: boolean;
54
- /** True if a network request is currently active. */
55
- isLoading: boolean;
56
- }
57
- /**
58
- * Custom fetch implementation, compatible with `window.fetch`.
59
- * Useful for server-side usage or testing.
60
- */
61
- type Fetcher = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
62
- /**
63
- * Configuration for Infer Core.
64
- */
65
- interface InferConfig {
66
- /**
67
- * Pro6PP Authorization Key.
68
- */
69
- authKey: string;
70
- /**
71
- * Country to search addresses in.
72
- */
73
- country: CountryCode;
74
- /**
75
- * Base URL for the Pro6PP API.
76
- * Useful for proxying requests through your own backend.
77
- * @default 'https://api.pro6pp.nl/v2'
78
- */
79
- apiUrl?: string;
80
- /**
81
- * Custom fetch implementation.
82
- * Useful for server-side usage or testing.
83
- */
84
- fetcher?: Fetcher;
85
- /**
86
- * Maximum number of results to return.
87
- * @default 1000
88
- */
89
- limit?: number;
90
- /**
91
- * Callback fired when the internal state changes.
92
- */
93
- onStateChange?: (state: InferState) => void;
94
- /**
95
- * Callback fired when a user selects a full valid address.
96
- */
97
- onSelect?: (selection: AddressValue | string | null) => void;
98
- }
99
-
100
- declare const INITIAL_STATE: InferState;
101
- declare class InferCore {
102
- private country;
103
- private authKey;
104
- private apiUrl;
105
- private limit;
106
- private fetcher;
107
- private onStateChange;
108
- private onSelect;
109
- state: InferState;
110
- private abortController;
111
- private debouncedFetch;
112
- constructor(config: InferConfig);
113
- handleInput(value: string): void;
114
- handleKeyDown(event: KeyboardEvent | React.KeyboardEvent<HTMLInputElement>): void;
115
- selectItem(item: InferResult | string): void;
116
- private shouldAutoInsertComma;
117
- private finishSelection;
118
- private processSelection;
119
- private executeFetch;
120
- private mapResponseToState;
121
- private updateQueryAndFetch;
122
- private replaceLastSegment;
123
- private getQueryPrefix;
124
- private getCurrentFragment;
125
- private resetState;
126
- private updateState;
127
- private debounce;
128
- }
129
-
130
- export { type AddressValue, type CountryCode, type Fetcher, INITIAL_STATE, type InferConfig, InferCore, type InferResult, type InferState, type Stage };