@searchspring/snap-client 0.20.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.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +174 -0
  3. package/dist/cjs/Client/Client.d.ts +15 -0
  4. package/dist/cjs/Client/Client.d.ts.map +1 -0
  5. package/dist/cjs/Client/Client.js +198 -0
  6. package/dist/cjs/Client/NetworkCache/NetworkCache.d.ts +10 -0
  7. package/dist/cjs/Client/NetworkCache/NetworkCache.d.ts.map +1 -0
  8. package/dist/cjs/Client/NetworkCache/NetworkCache.js +104 -0
  9. package/dist/cjs/Client/apis/Abstract.d.ts +49 -0
  10. package/dist/cjs/Client/apis/Abstract.d.ts.map +1 -0
  11. package/dist/cjs/Client/apis/Abstract.js +209 -0
  12. package/dist/cjs/Client/apis/Hybrid.d.ts +10 -0
  13. package/dist/cjs/Client/apis/Hybrid.d.ts.map +1 -0
  14. package/dist/cjs/Client/apis/Hybrid.js +137 -0
  15. package/dist/cjs/Client/apis/Legacy.d.ts +11 -0
  16. package/dist/cjs/Client/apis/Legacy.d.ts.map +1 -0
  17. package/dist/cjs/Client/apis/Legacy.js +147 -0
  18. package/dist/cjs/Client/apis/Recommend.d.ts +81 -0
  19. package/dist/cjs/Client/apis/Recommend.d.ts.map +1 -0
  20. package/dist/cjs/Client/apis/Recommend.js +222 -0
  21. package/dist/cjs/Client/apis/Snap.d.ts +8 -0
  22. package/dist/cjs/Client/apis/Snap.d.ts.map +1 -0
  23. package/dist/cjs/Client/apis/Snap.js +126 -0
  24. package/dist/cjs/Client/apis/Suggest.d.ts +45 -0
  25. package/dist/cjs/Client/apis/Suggest.d.ts.map +1 -0
  26. package/dist/cjs/Client/apis/Suggest.js +145 -0
  27. package/dist/cjs/Client/apis/index.d.ts +7 -0
  28. package/dist/cjs/Client/apis/index.d.ts.map +1 -0
  29. package/dist/cjs/Client/apis/index.js +18 -0
  30. package/dist/cjs/Client/transforms/index.d.ts +4 -0
  31. package/dist/cjs/Client/transforms/index.d.ts.map +1 -0
  32. package/dist/cjs/Client/transforms/index.js +15 -0
  33. package/dist/cjs/Client/transforms/searchRequest.d.ts +47 -0
  34. package/dist/cjs/Client/transforms/searchRequest.d.ts.map +1 -0
  35. package/dist/cjs/Client/transforms/searchRequest.js +151 -0
  36. package/dist/cjs/Client/transforms/searchResponse.d.ts +31 -0
  37. package/dist/cjs/Client/transforms/searchResponse.d.ts.map +1 -0
  38. package/dist/cjs/Client/transforms/searchResponse.js +246 -0
  39. package/dist/cjs/Client/transforms/suggestResponse.d.ts +29 -0
  40. package/dist/cjs/Client/transforms/suggestResponse.d.ts.map +1 -0
  41. package/dist/cjs/Client/transforms/suggestResponse.js +53 -0
  42. package/dist/cjs/Client/utils/charsParams.d.ts +3 -0
  43. package/dist/cjs/Client/utils/charsParams.d.ts.map +1 -0
  44. package/dist/cjs/Client/utils/charsParams.js +23 -0
  45. package/dist/cjs/Client/utils/fibonacci.d.ts +2 -0
  46. package/dist/cjs/Client/utils/fibonacci.d.ts.map +1 -0
  47. package/dist/cjs/Client/utils/fibonacci.js +14 -0
  48. package/dist/cjs/Client/utils/hashParams.d.ts +3 -0
  49. package/dist/cjs/Client/utils/hashParams.d.ts.map +1 -0
  50. package/dist/cjs/Client/utils/hashParams.js +10 -0
  51. package/dist/cjs/Client/utils/htmlUnescape.d.ts +2 -0
  52. package/dist/cjs/Client/utils/htmlUnescape.d.ts.map +1 -0
  53. package/dist/cjs/Client/utils/htmlUnescape.js +12 -0
  54. package/dist/cjs/Client/utils/index.d.ts +2 -0
  55. package/dist/cjs/Client/utils/index.d.ts.map +1 -0
  56. package/dist/cjs/Client/utils/index.js +13 -0
  57. package/dist/cjs/Client/utils/mergeParams.d.ts +2 -0
  58. package/dist/cjs/Client/utils/mergeParams.d.ts.map +1 -0
  59. package/dist/cjs/Client/utils/mergeParams.js +18 -0
  60. package/dist/cjs/index.d.ts +3 -0
  61. package/dist/cjs/index.d.ts.map +1 -0
  62. package/dist/cjs/index.js +13 -0
  63. package/dist/cjs/types.d.ts +45 -0
  64. package/dist/cjs/types.d.ts.map +1 -0
  65. package/dist/cjs/types.js +2 -0
  66. package/dist/esm/Client/Client.d.ts +15 -0
  67. package/dist/esm/Client/Client.d.ts.map +1 -0
  68. package/dist/esm/Client/Client.js +108 -0
  69. package/dist/esm/Client/NetworkCache/NetworkCache.d.ts +10 -0
  70. package/dist/esm/Client/NetworkCache/NetworkCache.d.ts.map +1 -0
  71. package/dist/esm/Client/NetworkCache/NetworkCache.js +89 -0
  72. package/dist/esm/Client/apis/Abstract.d.ts +49 -0
  73. package/dist/esm/Client/apis/Abstract.d.ts.map +1 -0
  74. package/dist/esm/Client/apis/Abstract.js +119 -0
  75. package/dist/esm/Client/apis/Hybrid.d.ts +10 -0
  76. package/dist/esm/Client/apis/Hybrid.d.ts.map +1 -0
  77. package/dist/esm/Client/apis/Hybrid.js +49 -0
  78. package/dist/esm/Client/apis/Legacy.d.ts +11 -0
  79. package/dist/esm/Client/apis/Legacy.d.ts.map +1 -0
  80. package/dist/esm/Client/apis/Legacy.js +44 -0
  81. package/dist/esm/Client/apis/Recommend.d.ts +81 -0
  82. package/dist/esm/Client/apis/Recommend.d.ts.map +1 -0
  83. package/dist/esm/Client/apis/Recommend.js +91 -0
  84. package/dist/esm/Client/apis/Snap.d.ts +8 -0
  85. package/dist/esm/Client/apis/Snap.d.ts.map +1 -0
  86. package/dist/esm/Client/apis/Snap.js +36 -0
  87. package/dist/esm/Client/apis/Suggest.d.ts +45 -0
  88. package/dist/esm/Client/apis/Suggest.d.ts.map +1 -0
  89. package/dist/esm/Client/apis/Suggest.js +45 -0
  90. package/dist/esm/Client/apis/index.d.ts +7 -0
  91. package/dist/esm/Client/apis/index.d.ts.map +1 -0
  92. package/dist/esm/Client/apis/index.js +6 -0
  93. package/dist/esm/Client/transforms/index.d.ts +4 -0
  94. package/dist/esm/Client/transforms/index.d.ts.map +1 -0
  95. package/dist/esm/Client/transforms/index.js +3 -0
  96. package/dist/esm/Client/transforms/searchRequest.d.ts +47 -0
  97. package/dist/esm/Client/transforms/searchRequest.d.ts.map +1 -0
  98. package/dist/esm/Client/transforms/searchRequest.js +133 -0
  99. package/dist/esm/Client/transforms/searchResponse.d.ts +31 -0
  100. package/dist/esm/Client/transforms/searchResponse.d.ts.map +1 -0
  101. package/dist/esm/Client/transforms/searchResponse.js +249 -0
  102. package/dist/esm/Client/transforms/suggestResponse.d.ts +29 -0
  103. package/dist/esm/Client/transforms/suggestResponse.d.ts.map +1 -0
  104. package/dist/esm/Client/transforms/suggestResponse.js +42 -0
  105. package/dist/esm/Client/utils/charsParams.d.ts +3 -0
  106. package/dist/esm/Client/utils/charsParams.d.ts.map +1 -0
  107. package/dist/esm/Client/utils/charsParams.js +19 -0
  108. package/dist/esm/Client/utils/fibonacci.d.ts +2 -0
  109. package/dist/esm/Client/utils/fibonacci.d.ts.map +1 -0
  110. package/dist/esm/Client/utils/fibonacci.js +10 -0
  111. package/dist/esm/Client/utils/hashParams.d.ts +3 -0
  112. package/dist/esm/Client/utils/hashParams.d.ts.map +1 -0
  113. package/dist/esm/Client/utils/hashParams.js +6 -0
  114. package/dist/esm/Client/utils/htmlUnescape.d.ts +2 -0
  115. package/dist/esm/Client/utils/htmlUnescape.d.ts.map +1 -0
  116. package/dist/esm/Client/utils/htmlUnescape.js +8 -0
  117. package/dist/esm/Client/utils/index.d.ts +2 -0
  118. package/dist/esm/Client/utils/index.d.ts.map +1 -0
  119. package/dist/esm/Client/utils/index.js +1 -0
  120. package/dist/esm/Client/utils/mergeParams.d.ts +2 -0
  121. package/dist/esm/Client/utils/mergeParams.d.ts.map +1 -0
  122. package/dist/esm/Client/utils/mergeParams.js +10 -0
  123. package/dist/esm/index.d.ts +3 -0
  124. package/dist/esm/index.d.ts.map +1 -0
  125. package/dist/esm/index.js +1 -0
  126. package/dist/esm/types.d.ts +45 -0
  127. package/dist/esm/types.d.ts.map +1 -0
  128. package/dist/esm/types.js +1 -0
  129. package/package.json +27 -0
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.querystring = exports.ApiConfiguration = exports.API = void 0;
40
+ var fibonacci_1 = require("../utils/fibonacci");
41
+ var NetworkCache_1 = require("../NetworkCache/NetworkCache");
42
+ var isBlob = function (value) { return typeof Blob !== 'undefined' && value instanceof Blob; };
43
+ var API = /** @class */ (function () {
44
+ function API(configuration) {
45
+ var _this = this;
46
+ this.configuration = configuration;
47
+ this.retryDelay = 1000;
48
+ this.retryCount = 1;
49
+ this.fetchApi = function (url, init) { return __awaiter(_this, void 0, void 0, function () {
50
+ var response;
51
+ return __generator(this, function (_a) {
52
+ switch (_a.label) {
53
+ case 0: return [4 /*yield*/, this.configuration.fetchApi(url, init)];
54
+ case 1:
55
+ response = _a.sent();
56
+ return [2 /*return*/, response];
57
+ }
58
+ });
59
+ }); };
60
+ this.cache = new NetworkCache_1.NetworkCache(configuration.cacheSettings);
61
+ }
62
+ API.prototype.request = function (context, cacheKey) {
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ var _a, url, init, cachedResponse, response, responseJSON;
65
+ var _this = this;
66
+ return __generator(this, function (_b) {
67
+ switch (_b.label) {
68
+ case 0:
69
+ _a = this.createFetchParams(context), url = _a.url, init = _a.init;
70
+ if (cacheKey) {
71
+ cachedResponse = this.cache.get(cacheKey);
72
+ if (cachedResponse) {
73
+ this.retryCount = 0; // reset count and delay incase rate limit occurs again before a page refresh
74
+ this.retryDelay = 1000;
75
+ return [2 /*return*/, cachedResponse];
76
+ }
77
+ }
78
+ return [4 /*yield*/, this.fetchApi(url, init)];
79
+ case 1:
80
+ response = _b.sent();
81
+ return [4 /*yield*/, response.json()];
82
+ case 2:
83
+ responseJSON = _b.sent();
84
+ if (!(response.status >= 200 && response.status < 300)) return [3 /*break*/, 3];
85
+ this.retryCount = 0; // reset count and delay incase rate limit occurs again before a page refresh
86
+ this.retryDelay = 1000;
87
+ if (cacheKey) {
88
+ // save in the cache before returning
89
+ this.cache.set(cacheKey, responseJSON);
90
+ }
91
+ return [2 /*return*/, responseJSON];
92
+ case 3:
93
+ if (!(response.status == 429)) return [3 /*break*/, 7];
94
+ if (!(this.retryCount < this.configuration.maxRetry)) return [3 /*break*/, 6];
95
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, _this.retryDelay); })];
96
+ case 4:
97
+ _b.sent(); // delay retry
98
+ this.retryDelay = (0, fibonacci_1.fibonacci)(this.retryCount) * 1000;
99
+ this.retryCount++;
100
+ return [4 /*yield*/, this.request(context, cacheKey)];
101
+ case 5: return [2 /*return*/, _b.sent()];
102
+ case 6: throw response.status;
103
+ case 7: throw response.status;
104
+ }
105
+ });
106
+ });
107
+ };
108
+ API.prototype.createFetchParams = function (context) {
109
+ var _a, _b;
110
+ // grab siteID out of context to generate apiHost fo URL
111
+ var siteId = ((_a = context === null || context === void 0 ? void 0 : context.body) === null || _a === void 0 ? void 0 : _a.siteId) || ((_b = context === null || context === void 0 ? void 0 : context.query) === null || _b === void 0 ? void 0 : _b.siteId);
112
+ if (!siteId) {
113
+ throw new Error("Request failed. Missing \"siteId\" parameter.");
114
+ }
115
+ var siteIdHost = "https://".concat(siteId, ".a.searchspring.io");
116
+ var origin = (this.configuration.origin || siteIdHost).replace(/\/$/, '');
117
+ var url = "".concat(origin, "/").concat(context.path.replace(/^\//, ''));
118
+ if (context.query !== undefined && Object.keys(context.query).length !== 0) {
119
+ // only add the querystring to the URL if there are query parameters.
120
+ url += '?' + this.configuration.queryParamsStringify(context.query);
121
+ }
122
+ var body = (typeof FormData !== 'undefined' && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)
123
+ ? context.body
124
+ : JSON.stringify(context.body);
125
+ var headers = Object.assign({}, this.configuration.headers, context.headers);
126
+ var init = {
127
+ method: context.method,
128
+ headers: headers,
129
+ body: body,
130
+ };
131
+ return { url: url, init: init };
132
+ };
133
+ return API;
134
+ }());
135
+ exports.API = API;
136
+ var ApiConfiguration = /** @class */ (function () {
137
+ function ApiConfiguration(configuration) {
138
+ this.configuration = configuration;
139
+ if (!configuration.maxRetry) {
140
+ this.configuration.maxRetry = 8;
141
+ }
142
+ }
143
+ Object.defineProperty(ApiConfiguration.prototype, "cacheSettings", {
144
+ get: function () {
145
+ return this.configuration.cacheSettings;
146
+ },
147
+ enumerable: false,
148
+ configurable: true
149
+ });
150
+ Object.defineProperty(ApiConfiguration.prototype, "maxRetry", {
151
+ get: function () {
152
+ return this.configuration.maxRetry;
153
+ },
154
+ enumerable: false,
155
+ configurable: true
156
+ });
157
+ Object.defineProperty(ApiConfiguration.prototype, "origin", {
158
+ get: function () {
159
+ return this.configuration.origin;
160
+ },
161
+ enumerable: false,
162
+ configurable: true
163
+ });
164
+ Object.defineProperty(ApiConfiguration.prototype, "fetchApi", {
165
+ get: function () {
166
+ return this.configuration.fetchApi || window.fetch.bind(window);
167
+ },
168
+ enumerable: false,
169
+ configurable: true
170
+ });
171
+ Object.defineProperty(ApiConfiguration.prototype, "queryParamsStringify", {
172
+ get: function () {
173
+ return this.configuration.queryParamsStringify || querystring;
174
+ },
175
+ enumerable: false,
176
+ configurable: true
177
+ });
178
+ Object.defineProperty(ApiConfiguration.prototype, "headers", {
179
+ get: function () {
180
+ return this.configuration.headers;
181
+ },
182
+ enumerable: false,
183
+ configurable: true
184
+ });
185
+ return ApiConfiguration;
186
+ }());
187
+ exports.ApiConfiguration = ApiConfiguration;
188
+ function querystring(params, prefix) {
189
+ if (prefix === void 0) { prefix = ''; }
190
+ return Object.keys(params)
191
+ .map(function (key) {
192
+ var fullKey = prefix + (prefix.length ? "[".concat(key, "]") : key);
193
+ var value = params[key];
194
+ if (value instanceof Array) {
195
+ var multiValue = value.map(function (singleValue) { return encodeURIComponent(String(singleValue)); }).join("&".concat(encodeURIComponent(fullKey), "="));
196
+ return "".concat(encodeURIComponent(fullKey), "=").concat(multiValue);
197
+ }
198
+ if (value instanceof Date) {
199
+ return "".concat(encodeURIComponent(fullKey), "=").concat(encodeURIComponent(value.toISOString()));
200
+ }
201
+ if (value instanceof Object) {
202
+ return querystring(value, fullKey);
203
+ }
204
+ return "".concat(encodeURIComponent(fullKey), "=").concat(encodeURIComponent(String(value)));
205
+ })
206
+ .filter(function (part) { return part.length > 0; })
207
+ .join('&');
208
+ }
209
+ exports.querystring = querystring;
@@ -0,0 +1,10 @@
1
+ import { AutocompleteRequestModel, AutocompleteResponseModel, MetaRequestModel, MetaResponseModel, SearchRequestModel, SearchResponseModel } from '@searchspring/snapi-types';
2
+ import { API, ApiConfiguration } from '.';
3
+ export declare class HybridAPI extends API {
4
+ private requesters;
5
+ constructor(configuration: ApiConfiguration);
6
+ getMeta(requestParameters: MetaRequestModel): Promise<MetaResponseModel>;
7
+ getSearch(requestParameters: SearchRequestModel): Promise<SearchResponseModel>;
8
+ getAutocomplete(requestParameters: AutocompleteRequestModel): Promise<AutocompleteResponseModel>;
9
+ }
10
+ //# sourceMappingURL=Hybrid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Hybrid.d.ts","sourceRoot":"","sources":["../../../../src/Client/apis/Hybrid.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,GAAG,EAAsC,gBAAgB,EAA6C,MAAM,GAAG,CAAC;AAGzH,qBAAa,SAAU,SAAQ,GAAG;IACjC,OAAO,CAAC,UAAU,CAGhB;gBAEU,aAAa,EAAE,gBAAgB;IASrC,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAKxE,SAAS,CAAC,iBAAiB,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAQ9E,eAAe,CAAC,iBAAiB,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;CAoCtG"}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.HybridAPI = void 0;
66
+ var _1 = require(".");
67
+ var transforms_1 = require("../transforms");
68
+ var HybridAPI = /** @class */ (function (_super) {
69
+ __extends(HybridAPI, _super);
70
+ function HybridAPI(configuration) {
71
+ var _this = _super.call(this, configuration) || this;
72
+ _this.requesters = {
73
+ legacy: new _1.LegacyAPI(new _1.ApiConfiguration({ origin: configuration.origin, cacheSettings: _this.configuration.cacheSettings })),
74
+ suggest: new _1.SuggestAPI(new _1.ApiConfiguration({ origin: configuration.origin, cacheSettings: _this.configuration.cacheSettings })),
75
+ };
76
+ return _this;
77
+ }
78
+ HybridAPI.prototype.getMeta = function (requestParameters) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ var legacyRequestParameters;
81
+ return __generator(this, function (_a) {
82
+ legacyRequestParameters = requestParameters;
83
+ return [2 /*return*/, this.requesters.legacy.getMeta(legacyRequestParameters)];
84
+ });
85
+ });
86
+ };
87
+ HybridAPI.prototype.getSearch = function (requestParameters) {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var legacyRequestParameters, legacyData;
90
+ return __generator(this, function (_a) {
91
+ switch (_a.label) {
92
+ case 0:
93
+ legacyRequestParameters = (0, transforms_1.transformSearchRequest)(requestParameters);
94
+ return [4 /*yield*/, this.requesters.legacy.getSearch(legacyRequestParameters)];
95
+ case 1:
96
+ legacyData = _a.sent();
97
+ return [2 /*return*/, (0, transforms_1.transformSearchResponse)(legacyData, requestParameters)];
98
+ }
99
+ });
100
+ });
101
+ };
102
+ HybridAPI.prototype.getAutocomplete = function (requestParameters) {
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ var legacyRequestParameters, suggestParams, suggestResults, transformedSuggestResults, q, queryParameters, legacyResults, searchResults;
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0:
108
+ legacyRequestParameters = (0, transforms_1.transformSearchRequest)(requestParameters);
109
+ suggestParams = {
110
+ siteId: legacyRequestParameters.siteId,
111
+ language: 'en',
112
+ query: legacyRequestParameters.q,
113
+ suggestionCount: (requestParameters.suggestions || {}).count || 5,
114
+ };
115
+ if (!((requestParameters.search || {}).query || {}).spellCorrection) {
116
+ suggestParams.disableSpellCorrect = true;
117
+ }
118
+ return [4 /*yield*/, this.requesters.suggest.getSuggest(suggestParams)];
119
+ case 1:
120
+ suggestResults = _a.sent();
121
+ transformedSuggestResults = (0, transforms_1.transformSuggestResponse)(suggestResults);
122
+ q = (suggestResults.suggested || {}).text || transformedSuggestResults.correctedQuery || suggestResults.query;
123
+ queryParameters = __assign(__assign({}, legacyRequestParameters), { redirectResponse: 'full', q: q });
124
+ return [4 /*yield*/, this.requesters.legacy.getAutocomplete(queryParameters)];
125
+ case 2:
126
+ legacyResults = _a.sent();
127
+ searchResults = (0, transforms_1.transformSearchResponse)(legacyResults, requestParameters);
128
+ return [2 /*return*/, __assign(__assign({}, searchResults), { search: {
129
+ query: q,
130
+ }, autocomplete: transformedSuggestResults })];
131
+ }
132
+ });
133
+ });
134
+ };
135
+ return HybridAPI;
136
+ }(_1.API));
137
+ exports.HybridAPI = HybridAPI;
@@ -0,0 +1,11 @@
1
+ import { MetaRequestModel, MetaResponseModel } from '@searchspring/snapi-types';
2
+ import { API } from '.';
3
+ export declare class LegacyAPI extends API {
4
+ private getEndpoint;
5
+ postMeta(requestParameters: MetaRequestModel): Promise<MetaResponseModel>;
6
+ getMeta(queryParameters: MetaRequestModel): Promise<MetaResponseModel>;
7
+ getSearch(queryParameters: any): Promise<any>;
8
+ getAutocomplete(queryParameters: any): Promise<any>;
9
+ getFinder(queryParameters: any): Promise<any>;
10
+ }
11
+ //# sourceMappingURL=Legacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Legacy.d.ts","sourceRoot":"","sources":["../../../../src/Client/apis/Legacy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEhF,OAAO,EAAE,GAAG,EAA0B,MAAM,GAAG,CAAC;AAEhD,qBAAa,SAAU,SAAQ,GAAG;YACnB,WAAW;IAiBnB,QAAQ,CAAC,iBAAiB,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkBzE,OAAO,CAAC,eAAe,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAgBtE,SAAS,CAAC,eAAe,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAI7C,eAAe,CAAC,eAAe,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAInD,SAAS,CAAC,eAAe,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAGnD"}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.LegacyAPI = void 0;
55
+ var _1 = require(".");
56
+ var LegacyAPI = /** @class */ (function (_super) {
57
+ __extends(LegacyAPI, _super);
58
+ function LegacyAPI() {
59
+ return _super !== null && _super.apply(this, arguments) || this;
60
+ }
61
+ LegacyAPI.prototype.getEndpoint = function (queryParameters, path) {
62
+ if (path === void 0) { path = '/api/search/search.json'; }
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ var headerParameters, legacyResponse;
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
67
+ case 0:
68
+ queryParameters.resultsFormat = 'native';
69
+ headerParameters = {};
70
+ return [4 /*yield*/, this.request({
71
+ path: path,
72
+ method: 'GET',
73
+ headers: headerParameters,
74
+ query: queryParameters,
75
+ }, path + JSON.stringify(queryParameters))];
76
+ case 1:
77
+ legacyResponse = _a.sent();
78
+ return [2 /*return*/, legacyResponse];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ LegacyAPI.prototype.postMeta = function (requestParameters) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var headerParameters, response;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ headerParameters = {};
90
+ headerParameters['Content-Type'] = 'application/json';
91
+ return [4 /*yield*/, this.request({
92
+ path: '/api/meta/meta.json',
93
+ method: 'POST',
94
+ headers: headerParameters,
95
+ body: requestParameters,
96
+ }, '/api/meta/meta.json' + JSON.stringify(requestParameters))];
97
+ case 1:
98
+ response = _a.sent();
99
+ return [2 /*return*/, response];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ LegacyAPI.prototype.getMeta = function (queryParameters) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var headerParameters, response;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0:
110
+ headerParameters = {};
111
+ return [4 /*yield*/, this.request({
112
+ path: '/api/meta/meta.json',
113
+ method: 'GET',
114
+ headers: headerParameters,
115
+ query: queryParameters,
116
+ }, '/api/meta/meta.json' + JSON.stringify(queryParameters))];
117
+ case 1:
118
+ response = _a.sent();
119
+ return [2 /*return*/, response];
120
+ }
121
+ });
122
+ });
123
+ };
124
+ LegacyAPI.prototype.getSearch = function (queryParameters) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ return __generator(this, function (_a) {
127
+ return [2 /*return*/, this.getEndpoint(queryParameters, '/api/search/search.json')];
128
+ });
129
+ });
130
+ };
131
+ LegacyAPI.prototype.getAutocomplete = function (queryParameters) {
132
+ return __awaiter(this, void 0, void 0, function () {
133
+ return __generator(this, function (_a) {
134
+ return [2 /*return*/, this.getEndpoint(queryParameters, '/api/search/autocomplete.json')];
135
+ });
136
+ });
137
+ };
138
+ LegacyAPI.prototype.getFinder = function (queryParameters) {
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ return __generator(this, function (_a) {
141
+ return [2 /*return*/, this.getEndpoint(queryParameters, '/api/search/finder.json')];
142
+ });
143
+ });
144
+ };
145
+ return LegacyAPI;
146
+ }(_1.API));
147
+ exports.LegacyAPI = LegacyAPI;
@@ -0,0 +1,81 @@
1
+ import { API, ApiConfiguration } from './Abstract';
2
+ import { SearchResponseModelResult } from '@searchspring/snapi-types';
3
+ export declare type RecommendRequestModel = {
4
+ tags: string[];
5
+ siteId: string;
6
+ product?: string;
7
+ shopper?: string;
8
+ categories?: string[];
9
+ cart?: string[];
10
+ lastViewed?: string[];
11
+ test?: boolean;
12
+ batched?: boolean;
13
+ };
14
+ export declare type RecommendResponseModel = {
15
+ profile: {
16
+ tag: string;
17
+ };
18
+ results: SearchResponseModelResult[];
19
+ }[];
20
+ export declare type ProfileRequestModel = {
21
+ siteId: string;
22
+ tag: string;
23
+ branch?: string;
24
+ };
25
+ export declare type ProfileResponseModel = {
26
+ profile: {
27
+ tag: string;
28
+ placement: string;
29
+ display: {
30
+ threshold: number;
31
+ template: {
32
+ name: string;
33
+ uuid: string;
34
+ markup?: string;
35
+ styles?: string;
36
+ component?: string;
37
+ branch?: string;
38
+ group?: string;
39
+ };
40
+ templateParameters: {
41
+ [any: string]: unknown;
42
+ };
43
+ };
44
+ };
45
+ };
46
+ export declare type RecommendCombinedRequestModel = {
47
+ tag: string;
48
+ siteId: string;
49
+ product?: string;
50
+ shopper?: string;
51
+ categories?: string[];
52
+ cart?: string[];
53
+ lastViewed?: string[];
54
+ test?: boolean;
55
+ branch?: string;
56
+ };
57
+ declare class Deferred {
58
+ promise: Promise<any>;
59
+ resolve: any;
60
+ reject: any;
61
+ constructor();
62
+ }
63
+ export declare type RecommendCombinedResponseModel = ProfileResponseModel & {
64
+ results: SearchResponseModelResult[];
65
+ };
66
+ export declare class RecommendAPI extends API {
67
+ batches: {
68
+ [key: string]: {
69
+ timeout: number;
70
+ request: any;
71
+ deferreds?: Deferred[];
72
+ };
73
+ };
74
+ constructor(config: ApiConfiguration);
75
+ getProfile(queryParameters: ProfileRequestModel): Promise<ProfileResponseModel>;
76
+ batchRecommendations(parameters: RecommendRequestModel): Promise<RecommendResponseModel>;
77
+ getRecommendations(queryParameters: RecommendRequestModel): Promise<RecommendResponseModel>;
78
+ postRecommendations(requestParameters: RecommendRequestModel): Promise<RecommendResponseModel>;
79
+ }
80
+ export {};
81
+ //# sourceMappingURL=Recommend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Recommend.d.ts","sourceRoot":"","sources":["../../../../src/Client/apis/Recommend.ts"],"names":[],"mappings":"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"}