@brytdesigns/shopify-ajax-predictive-search-api 1.0.5 → 3.0.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/dist/effect/index.d.ts +312 -104
- package/dist/effect/index.js +11 -9
- package/dist/effect/index.js.map +1 -1
- package/dist/effect/schema.js +108 -135
- package/dist/effect/schema.js.map +1 -1
- package/dist/main/effect/index.js +11 -9
- package/dist/main/effect/index.js.map +1 -1
- package/dist/main/effect/schema.js +108 -135
- package/dist/main/effect/schema.js.map +1 -1
- package/dist/main/index.d.ts +397 -177
- package/dist/main/index.js +59 -36
- package/dist/main/index.js.map +1 -1
- package/package.json +14 -11
- package/dist/esm/index.js +0 -18275
- package/dist/esm/index.js.map +0 -1
package/dist/main/index.js
CHANGED
|
@@ -1,39 +1,62 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
minimumLogLevel = LogLevel.All;
|
|
15
|
-
}
|
|
16
|
-
const ajaxLayer = Layer.mergeAll(baseLayer, AjaxClient.Default);
|
|
17
|
-
return {
|
|
18
|
-
get: (input, options) => Effect.runPromise(
|
|
19
|
-
API.get(input, {
|
|
20
|
-
...options || {},
|
|
21
|
-
headers: {
|
|
22
|
-
"X-SDK-Variant-Source": "shopify-ajax-predictive-search-api",
|
|
23
|
-
"X-Library-Source": "brytdesigns-shopify-ajax-predictive-search-api",
|
|
24
|
-
...options?.headers || {}
|
|
25
|
-
}
|
|
26
|
-
}).pipe(
|
|
27
|
-
Logger.withMinimumLogLevel(minimumLogLevel),
|
|
28
|
-
Effect.provide(ajaxLayer)
|
|
29
|
-
),
|
|
30
|
-
{
|
|
31
|
-
signal: options?.signal
|
|
32
|
-
}
|
|
33
|
-
)
|
|
34
|
-
};
|
|
1
|
+
import { get } from "./effect/index.js";
|
|
2
|
+
import * as AjaxClient from "@brytdesigns/shopify-ajax-client";
|
|
3
|
+
import * as Cause from "effect/Cause";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Exit from "effect/Exit";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Logger from "effect/Logger";
|
|
8
|
+
import * as References from "effect/References";
|
|
9
|
+
//#region src/index.ts
|
|
10
|
+
/** Identifies this package on every request it makes. */
|
|
11
|
+
var SOURCE_HEADERS = {
|
|
12
|
+
"X-SDK-Variant-Source": "shopify-ajax-predictive-search-api",
|
|
13
|
+
"X-Library-Source": "brytdesigns-shopify-ajax-predictive-search-api"
|
|
35
14
|
};
|
|
36
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Creates a predictive search client.
|
|
17
|
+
*
|
|
18
|
+
* `get` resolves to the decoded results and **rejects** on failure. There is no
|
|
19
|
+
* `{ data, error }` envelope: a non-200 rejects with `AjaxResponseError`, and
|
|
20
|
+
* transport, encode and decode failures reject with Effect's own tagged errors.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Optional settings.
|
|
23
|
+
* @param options.debug - Enables request logging. Default `false`.
|
|
24
|
+
*/
|
|
25
|
+
var createPredictiveSearchApi = ({ debug = false, httpClient } = {}) => {
|
|
26
|
+
let baseLayer = Layer.empty;
|
|
27
|
+
let minimumLogLevel = "None";
|
|
28
|
+
if (debug) {
|
|
29
|
+
baseLayer = Logger.layer([Logger.consolePretty(), Logger.tracerLogger]);
|
|
30
|
+
minimumLogLevel = "All";
|
|
31
|
+
}
|
|
32
|
+
const ajaxLayer = Layer.mergeAll(baseLayer, httpClient ?? AjaxClient.layer);
|
|
33
|
+
/**
|
|
34
|
+
* Runs a request to a promise that rejects with the failure itself.
|
|
35
|
+
*
|
|
36
|
+
* `Effect.runPromise` rejects with a `FiberFailure` wrapping the error,
|
|
37
|
+
* which would force a plain-JS caller to understand Effect internals to get
|
|
38
|
+
* at their own tagged error. Squashing the cause means `catch (e)` sees the
|
|
39
|
+
* `AjaxResponseError` directly and `instanceof` behaves as expected.
|
|
40
|
+
*/
|
|
41
|
+
const settle = async (effect, signal) => {
|
|
42
|
+
const exit = await Effect.runPromiseExit(effect.pipe(Effect.provideService(References.MinimumLogLevel, minimumLogLevel), Effect.provide(ajaxLayer)), { signal });
|
|
43
|
+
if (Exit.isSuccess(exit)) return exit.value;
|
|
44
|
+
throw Cause.squash(exit.cause);
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
/**
|
|
48
|
+
* Runs a predictive search.
|
|
49
|
+
*
|
|
50
|
+
* @param input - The query, and which resources to search.
|
|
51
|
+
* @param options - An `AbortSignal` to cancel with, and custom headers.
|
|
52
|
+
* @returns A Promise resolving to the decoded results.
|
|
53
|
+
*/
|
|
54
|
+
get: (input, options) => settle(get(input).pipe(AjaxClient.withHeaders({
|
|
55
|
+
...SOURCE_HEADERS,
|
|
56
|
+
...options?.headers ?? {}
|
|
57
|
+
}), AjaxClient.execute), options?.signal) };
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
37
60
|
export { createPredictiveSearchApi };
|
|
38
|
-
|
|
61
|
+
|
|
39
62
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import * as AjaxClient from \"@brytdesigns/shopify-ajax-client\";\nimport * as Cause from \"effect/Cause\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport type { HttpClient } from \"effect/http\";\nimport * as Layer from \"effect/Layer\";\nimport * as Logger from \"effect/Logger\";\nimport type * as LogLevel from \"effect/LogLevel\";\nimport * as References from \"effect/References\";\nimport * as API from \"./effect/index.js\";\n\nexport namespace createPredictiveSearchApi {\n\texport type Options = {\n\t\tdebug?: boolean;\n\t\t/**\n\t\t * Replaces the HTTP layer.\n\t\t *\n\t\t * The default is `AjaxClient.layer`, which is `fetch`. Overriding it is\n\t\t * the only way to exercise this client without a network - the\n\t\t * alternative was spying on the `layer` export, which tests how the\n\t\t * module is wired rather than what it sends.\n\t\t */\n\t\thttpClient?: Layer.Layer<HttpClient.HttpClient>;\n\t};\n\n\texport type RequestOptions = {\n\t\tsignal?: AbortSignal;\n\t\theaders?: Record<string, string>;\n\t};\n}\n\n/** Identifies this package on every request it makes. */\nconst SOURCE_HEADERS = {\n\t\"X-SDK-Variant-Source\": \"shopify-ajax-predictive-search-api\",\n\t\"X-Library-Source\": \"brytdesigns-shopify-ajax-predictive-search-api\",\n} as const;\n\n/**\n * Creates a predictive search client.\n *\n * `get` resolves to the decoded results and **rejects** on failure. There is no\n * `{ data, error }` envelope: a non-200 rejects with `AjaxResponseError`, and\n * transport, encode and decode failures reject with Effect's own tagged errors.\n *\n * @param options - Optional settings.\n * @param options.debug - Enables request logging. Default `false`.\n */\nexport const createPredictiveSearchApi = ({\n\tdebug = false,\n\thttpClient,\n}: createPredictiveSearchApi.Options = {}) => {\n\tlet baseLayer: Layer.Layer<never> = Layer.empty;\n\t// v4 levels are string literals, and Logger.layer replaces the active set\n\t// rather than adding to it - tracerLogger keeps v3's built-in behaviour.\n\tlet minimumLogLevel: LogLevel.LogLevel = \"None\";\n\n\tif (debug) {\n\t\tbaseLayer = Logger.layer([Logger.consolePretty(), Logger.tracerLogger]);\n\t\tminimumLogLevel = \"All\";\n\t}\n\n\tconst ajaxLayer = Layer.mergeAll(baseLayer, httpClient ?? AjaxClient.layer);\n\n\t/**\n\t * Runs a request to a promise that rejects with the failure itself.\n\t *\n\t * `Effect.runPromise` rejects with a `FiberFailure` wrapping the error,\n\t * which would force a plain-JS caller to understand Effect internals to get\n\t * at their own tagged error. Squashing the cause means `catch (e)` sees the\n\t * `AjaxResponseError` directly and `instanceof` behaves as expected.\n\t */\n\tconst settle = async <A, E>(\n\t\teffect: Effect.Effect<A, E, HttpClient.HttpClient>,\n\t\tsignal?: AbortSignal,\n\t): Promise<A> => {\n\t\tconst exit = await Effect.runPromiseExit(\n\t\t\teffect.pipe(\n\t\t\t\tEffect.provideService(References.MinimumLogLevel, minimumLogLevel),\n\t\t\t\tEffect.provide(ajaxLayer),\n\t\t\t),\n\t\t\t{ signal },\n\t\t);\n\n\t\tif (Exit.isSuccess(exit)) return exit.value;\n\n\t\tthrow Cause.squash(exit.cause);\n\t};\n\n\treturn {\n\t\t/**\n\t\t * Runs a predictive search.\n\t\t *\n\t\t * @param input - The query, and which resources to search.\n\t\t * @param options - An `AbortSignal` to cancel with, and custom headers.\n\t\t * @returns A Promise resolving to the decoded results.\n\t\t */\n\t\tget: (\n\t\t\tinput?: API.get.Input,\n\t\t\toptions?: createPredictiveSearchApi.RequestOptions,\n\t\t) =>\n\t\t\tsettle(\n\t\t\t\tAPI.get(input).pipe(\n\t\t\t\t\tAjaxClient.withHeaders({\n\t\t\t\t\t\t...SOURCE_HEADERS,\n\t\t\t\t\t\t...(options?.headers ?? {}),\n\t\t\t\t\t}),\n\t\t\t\t\tAjaxClient.execute,\n\t\t\t\t),\n\t\t\t\toptions?.signal,\n\t\t\t),\n\t};\n};\n"],"mappings":";;;;;;;;;;AAgCA,IAAM,iBAAiB;CACtB,wBAAwB;CACxB,oBAAoB;AACrB;;;;;;;;;;;AAYA,IAAa,6BAA6B,EACzC,QAAQ,OACR,eACsC,CAAC,MAAM;CAC7C,IAAI,YAAgC,MAAM;CAG1C,IAAI,kBAAqC;CAEzC,IAAI,OAAO;EACV,YAAY,OAAO,MAAM,CAAC,OAAO,cAAc,GAAG,OAAO,YAAY,CAAC;EACtE,kBAAkB;CACnB;CAEA,MAAM,YAAY,MAAM,SAAS,WAAW,cAAc,WAAW,KAAK;;;;;;;;;CAU1E,MAAM,SAAS,OACd,QACA,WACgB;EAChB,MAAM,OAAO,MAAM,OAAO,eACzB,OAAO,KACN,OAAO,eAAe,WAAW,iBAAiB,eAAe,GACjE,OAAO,QAAQ,SAAS,CACzB,GACA,EAAE,OAAO,CACV;EAEA,IAAI,KAAK,UAAU,IAAI,GAAG,OAAO,KAAK;EAEtC,MAAM,MAAM,OAAO,KAAK,KAAK;CAC9B;CAEA,OAAO;;;;;;;;AAQN,MACC,OACA,YAEA,OACC,IAAQ,KAAK,CAAC,CAAC,KACd,WAAW,YAAY;EACtB,GAAG;EACH,GAAI,SAAS,WAAW,CAAC;CAC1B,CAAC,GACD,WAAW,OACZ,GACA,SAAS,MACV,EACF;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brytdesigns/shopify-ajax-predictive-search-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "The api for handling the ajax version of predictive search",
|
|
5
5
|
"main": "./dist/main/index.js",
|
|
6
6
|
"types": "./dist/main/index.d.ts",
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/main/index.d.ts",
|
|
14
|
-
"
|
|
14
|
+
"default": "./dist/main/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./effect": {
|
|
17
|
+
"types": "./dist/effect/index.d.ts",
|
|
18
|
+
"default": "./dist/effect/index.js"
|
|
15
19
|
}
|
|
16
20
|
},
|
|
17
21
|
"type": "module",
|
|
@@ -19,19 +23,18 @@
|
|
|
19
23
|
"author": "Bryt Designs",
|
|
20
24
|
"license": "ISC",
|
|
21
25
|
"devDependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"vitest": "^3.
|
|
26
|
+
"@repo/vite-config": "0.0.0",
|
|
27
|
+
"vite": "^8.2.2",
|
|
28
|
+
"vitest": "^3.2.7"
|
|
25
29
|
},
|
|
26
30
|
"dependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"@brytdesigns/shopify-utils": "1.2.22"
|
|
31
|
+
"@brytdesigns/shopify-ajax-client": "3.0.0",
|
|
32
|
+
"@brytdesigns/shopify-utils": "3.0.0",
|
|
33
|
+
"effect": "4.0.3",
|
|
34
|
+
"lz-string": "^1.5.0"
|
|
32
35
|
},
|
|
33
36
|
"scripts": {
|
|
34
|
-
"build": "
|
|
37
|
+
"build": "vite build && vite build --mode effect",
|
|
35
38
|
"dev": "tsx src/index.ts",
|
|
36
39
|
"typecheck": "tsc --noEmit",
|
|
37
40
|
"test": "vitest"
|