@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.
@@ -1,32 +1,148 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ import * as Cause from 'effect/Cause';
4
+ import * as Context from 'effect/Context';
5
+ import * as Data from 'effect/Data';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Layer from 'effect/Layer';
8
+ import * as LogLevel from 'effect/LogLevel';
9
+ import * as Pipeable from 'effect/Pipeable';
3
10
  import * as Schema from 'effect/Schema';
4
11
 
5
- export type Input = Schema.Schema.Encoded<typeof Input>;
6
- declare const Input: Schema.extend<Schema.Struct<{
7
- sections: Schema.optional<Schema.transform<Schema.Array$<typeof Schema.String>, typeof Schema.String>>;
8
- sections_url: Schema.optional<typeof Schema.String>;
9
- }>, Schema.Struct<{
10
- q: typeof Schema.String;
11
- resources: Schema.optional<Schema.Struct<{
12
- limit: Schema.optionalWith<Schema.filter<typeof Schema.Number>, {
13
- default: () => number;
14
- }>;
15
- limit_scope: Schema.optionalWith<Schema.Literal<[
12
+ declare const Input: Schema.Struct<{
13
+ readonly sections: Schema.optional<Schema.decodeTo<Schema.String, Schema.$Array<Schema.String>, never, never>>;
14
+ readonly sections_url: Schema.optional<Schema.String>;
15
+ }>;
16
+ export type UniqueKeys<T extends string> = T extends `${infer K},${infer Rest}` ? K | UniqueKeys<Rest> : T;
17
+ declare function makeResponseSchema<const T extends string>(input: T): Schema.$Record<Schema.Literals<UniqueKeys<T>[]>, Schema.NullOr<Schema.decodeTo<Schema.instanceOf<Element, Element>, Schema.String, never, never>>>;
18
+ declare const Origins: Context.Reference<readonly string[]>;
19
+ declare const layer$1: (origins: readonly string[]) => Layer.Layer<never>;
20
+ export interface IShopifyRoutes {
21
+ readonly account_addresses_url: string;
22
+ readonly account_login_url: string;
23
+ readonly account_logout_url: string;
24
+ readonly account_recover_url: string;
25
+ readonly account_register_url: string;
26
+ readonly account_url: string;
27
+ readonly all_products_collection_url: string;
28
+ readonly product_url: string;
29
+ readonly products_url: string;
30
+ readonly cart_add_url: string;
31
+ readonly cart_change_url: string;
32
+ readonly cart_clear_url: string;
33
+ readonly cart_update_url: string;
34
+ readonly cart_url: string;
35
+ readonly collections_url: string;
36
+ readonly predictive_search_url: string;
37
+ readonly product_recommendations_url: string;
38
+ readonly root_url: string;
39
+ readonly search_url: string;
40
+ readonly storefront_login_url: string;
41
+ }
42
+ export interface IStorefrontClientConfig {
43
+ readonly accessToken: string;
44
+ readonly shopName: string;
45
+ apiVersion: string;
46
+ }
47
+ declare const Defaults: IShopifyRoutes;
48
+ declare class ShopifyRoutes extends Data.Class<IShopifyRoutes> {
49
+ constructor();
50
+ }
51
+ declare const make: () => ShopifyRoutes;
52
+ declare const Routes: Context.Reference<IShopifyRoutes>;
53
+ declare const layer$2: (routes: IShopifyRoutes) => Layer.Layer<never>;
54
+ declare class StorefrontClientConfig extends Data.Class<IStorefrontClientConfig> {
55
+ constructor();
56
+ }
57
+ declare const make$1: () => StorefrontClientConfig;
58
+ declare const Origin: Context.Reference<string>;
59
+ declare const layer$3: (origin: string) => Layer.Layer<never>;
60
+ declare namespace Sections {
61
+ export { Input, makeResponseSchema };
62
+ }
63
+ declare namespace StorefrontOrigin {
64
+ export { Origin, layer$3 as layer$3 };
65
+ }
66
+ declare namespace AllowedRouteOrigins {
67
+ export { Origins, layer$1 as layer$1 };
68
+ }
69
+ declare namespace ShopifyRoutes$1 {
70
+ export { Defaults, Routes, ShopifyRoutes, layer$2 as layer$2, make };
71
+ }
72
+ declare namespace StorefrontClientConfig$1 {
73
+ export { StorefrontClientConfig, make$1 as make$1 };
74
+ }
75
+ declare namespace Window$1 {
76
+ export { AllowedRouteOrigins, ShopifyRoutes$1 as ShopifyRoutes$1, StorefrontClientConfig$1 as StorefrontClientConfig$1, StorefrontOrigin };
77
+ }
78
+ declare namespace Ajax {
79
+ export { Sections, Window$1 as Window$1 };
80
+ }
81
+ /**
82
+ * Every route's input extends Shopify's `sections` pair, decoded.
83
+ *
84
+ * Constraining the descriptor on this is what lets {@link execute} read
85
+ * `decodedInput.sections` and {@link withSections} write it without a cast.
86
+ */
87
+ export type AjaxInput = typeof Ajax.Sections.Input.Type;
88
+ /**
89
+ * The same input, encoded — which is what a descriptor actually carries.
90
+ *
91
+ * Worth stating plainly because the two differ in a way that bites:
92
+ * `sections` decodes from `ReadonlyArray<string>` to a comma-joined `string`,
93
+ * so the encoded side is the array. A descriptor holds encoded input, so
94
+ * {@link withSections} takes the array form.
95
+ */
96
+ export type AjaxInputEncoded = typeof Ajax.Sections.Input.Encoded;
97
+ declare const METHODS_BY_URL: {
98
+ readonly products_url: "get";
99
+ readonly product_url: "get";
100
+ readonly predictive_search_url: "get";
101
+ readonly product_recommendations_url: "get";
102
+ readonly cart_add_url: "post";
103
+ readonly cart_update_url: "post";
104
+ readonly cart_url: "get";
105
+ readonly cart_change_url: "post";
106
+ readonly cart_clear_url: "post";
107
+ };
108
+ export type ValidAjaxRoutes = keyof typeof METHODS_BY_URL;
109
+ declare const TypeIdSymbol: unique symbol;
110
+ export type TypeId = typeof TypeIdSymbol;
111
+ /**
112
+ * A description of a Shopify Ajax request, before it is run.
113
+ *
114
+ * The reason this type exists at all: headers, sections and input are consumed
115
+ * *inside* the request effect, so there is nothing to modify once that effect
116
+ * has been constructed. `pipe(getCart(), withHeaders(...))` can only work if
117
+ * the thing in the pipe is a description rather than an `Effect`. {@link execute}
118
+ * is where the description becomes one.
119
+ */
120
+ export interface AjaxRequest<A extends AjaxInput, I extends AjaxInputEncoded, RD, B, J, SD> extends Pipeable.Pipeable {
121
+ readonly [TypeIdSymbol]: TypeId;
122
+ readonly routeName: ValidAjaxRoutes;
123
+ readonly inputSchema: Schema.Codec<A, I, RD>;
124
+ readonly outputSchema: (sections?: string) => Schema.Codec<B, J, SD>;
125
+ readonly input: I;
126
+ readonly headers: Readonly<Record<string, string>>;
127
+ }
128
+ type Input$1 = Schema.Codec.Encoded<typeof Input$1>;
129
+ declare const Input$1: Schema.Struct<{
130
+ readonly sections: Schema.optional<Schema.decodeTo<Schema.String, Schema.$Array<Schema.String>, never, never>>;
131
+ readonly sections_url: Schema.optional<Schema.String>;
132
+ readonly q: Schema.String;
133
+ readonly resources: Schema.optional<Schema.Struct<{
134
+ readonly limit: Schema.withDecodingDefaultType<Schema.Number, never>;
135
+ readonly limit_scope: Schema.withDecodingDefaultType<Schema.Literals<readonly [
16
136
  "all",
17
137
  "each"
18
- ]>, {
19
- default: () => "all";
20
- }>;
21
- options: Schema.optional<Schema.Struct<{
22
- unavailable_products: Schema.optionalWith<Schema.Literal<[
138
+ ]>, never>;
139
+ readonly options: Schema.optional<Schema.Struct<{
140
+ readonly unavailable_products: Schema.withDecodingDefaultType<Schema.Literals<readonly [
23
141
  "show",
24
142
  "hide",
25
143
  "last"
26
- ]>, {
27
- default: () => "last";
28
- }>;
29
- fields: Schema.optional<Schema.transform<Schema.Array$<Schema.Literal<[
144
+ ]>, never>;
145
+ readonly fields: Schema.optional<Schema.decodeTo<Schema.String, Schema.$Array<Schema.Literals<readonly [
30
146
  "author",
31
147
  "body",
32
148
  "product_type",
@@ -36,17 +152,38 @@ declare const Input: Schema.extend<Schema.Struct<{
36
152
  "variants.sku",
37
153
  "variants.title",
38
154
  "vendor"
39
- ]>>, typeof Schema.String>>;
155
+ ]>>, never, never>>;
40
156
  }>>;
41
157
  }>>;
42
- }>>;
158
+ }>;
43
159
  export declare namespace get {
44
- type Input = Input;
160
+ type Input = Input$1;
45
161
  }
46
- export declare const get: (input?: ({
162
+ export declare const get: (input?: {
163
+ readonly q: string;
164
+ readonly resources?: {
165
+ readonly limit?: number | undefined;
166
+ readonly limit_scope?: "all" | "each" | undefined;
167
+ readonly options?: {
168
+ readonly unavailable_products?: "show" | "hide" | "last" | undefined;
169
+ readonly fields?: readonly ("author" | "body" | "product_type" | "tag" | "title" | "variants.barcode" | "variants.sku" | "variants.title" | "vendor")[] | undefined;
170
+ } | undefined;
171
+ } | undefined;
47
172
  readonly sections?: readonly string[] | undefined;
48
173
  readonly sections_url?: string | undefined;
49
- } & {
174
+ } | undefined) => AjaxRequest<{
175
+ readonly q: string;
176
+ readonly resources?: {
177
+ readonly limit: number;
178
+ readonly limit_scope: "all" | "each";
179
+ readonly options?: {
180
+ readonly unavailable_products: "show" | "hide" | "last";
181
+ readonly fields?: string | undefined;
182
+ } | undefined;
183
+ } | undefined;
184
+ readonly sections?: string | undefined;
185
+ readonly sections_url?: string | undefined;
186
+ }, {
50
187
  readonly q: string;
51
188
  readonly resources?: {
52
189
  readonly limit?: number | undefined;
@@ -56,33 +193,39 @@ export declare const get: (input?: ({
56
193
  readonly fields?: readonly ("author" | "body" | "product_type" | "tag" | "title" | "variants.barcode" | "variants.sku" | "variants.title" | "vendor")[] | undefined;
57
194
  } | undefined;
58
195
  } | undefined;
59
- }) | undefined, options?: {
60
- headers?: Record<string, string>;
61
- }) => import("effect/Effect").Effect<{
62
- readonly data?: undefined;
63
- readonly error?: {
64
- status: number;
65
- message: string;
66
- description?: string;
67
- } | undefined;
68
- } | {
69
- readonly data?: {
70
- readonly resources: {
71
- readonly results: {
72
- readonly queries: readonly {
73
- readonly url: string;
74
- readonly text: string;
75
- readonly styled_text: string;
76
- }[];
77
- readonly products: readonly {
78
- readonly body: string;
79
- readonly title: string;
80
- readonly vendor: string | null;
81
- readonly url: string;
196
+ readonly sections?: readonly string[] | undefined;
197
+ readonly sections_url?: string | undefined;
198
+ }, never, {
199
+ readonly resources: {
200
+ readonly results: {
201
+ readonly queries: readonly {
202
+ readonly url: string;
203
+ readonly text: string;
204
+ readonly styled_text: string;
205
+ }[];
206
+ readonly products: readonly {
207
+ readonly available: boolean;
208
+ readonly body: string;
209
+ readonly compare_at_price_max: number;
210
+ readonly compare_at_price_min: number;
211
+ readonly handle: string;
212
+ readonly id: string | number;
213
+ readonly image: string | null;
214
+ readonly price: number;
215
+ readonly price_max: number;
216
+ readonly price_min: number;
217
+ readonly tags: readonly string[];
218
+ readonly title: string;
219
+ readonly type: string;
220
+ readonly url: string;
221
+ readonly variants: readonly {
82
222
  readonly available: boolean;
223
+ readonly compare_at_price: number | null;
83
224
  readonly id: string | number;
84
225
  readonly image: string | null;
85
226
  readonly price: number;
227
+ readonly title: string;
228
+ readonly url: string;
86
229
  readonly featured_image: {
87
230
  readonly aspect_ratio: number | null;
88
231
  readonly alt: string | null;
@@ -90,35 +233,85 @@ export declare const get: (input?: ({
90
233
  readonly url: string | null;
91
234
  readonly width: number | null;
92
235
  };
93
- readonly compare_at_price_max: number;
94
- readonly compare_at_price_min: number;
95
- readonly handle: string;
96
- readonly price_max: number;
97
- readonly price_min: number;
98
- readonly tags: readonly string[];
99
- readonly type: string;
100
- readonly variants: readonly {
101
- readonly title: string;
102
- readonly url: string;
103
- readonly available: boolean;
104
- readonly compare_at_price: number | null;
105
- readonly id: string | number;
106
- readonly image: string | null;
107
- readonly price: number;
108
- readonly featured_image: {
109
- readonly aspect_ratio: number | null;
110
- readonly alt: string | null;
111
- readonly height: number | null;
112
- readonly url: string | null;
113
- readonly width: number | null;
114
- };
115
- }[];
116
236
  }[];
117
- readonly collections: readonly {
118
- readonly body: string;
237
+ readonly vendor: string | null;
238
+ readonly featured_image: {
239
+ readonly aspect_ratio: number | null;
240
+ readonly alt: string | null;
241
+ readonly height: number | null;
242
+ readonly url: string | null;
243
+ readonly width: number | null;
244
+ };
245
+ }[];
246
+ readonly collections: readonly {
247
+ readonly body: string;
248
+ readonly handle: string;
249
+ readonly id: string | number;
250
+ readonly featured_image: {
251
+ readonly aspect_ratio: number | null;
252
+ readonly alt: string | null;
253
+ readonly height: number | null;
254
+ readonly url: string | null;
255
+ readonly width: number | null;
256
+ };
257
+ readonly published_at: Date;
258
+ readonly title: string;
259
+ readonly url: string;
260
+ }[];
261
+ readonly pages: readonly {
262
+ readonly author: string;
263
+ readonly body: string;
264
+ readonly handle: string;
265
+ readonly id: string | number;
266
+ readonly published_at: Date;
267
+ readonly title: string;
268
+ readonly url: string;
269
+ }[];
270
+ readonly articles: readonly {
271
+ readonly author: string;
272
+ readonly body: string;
273
+ readonly handle: string;
274
+ readonly id: string | number;
275
+ readonly published_at: Date;
276
+ readonly summary_html: string;
277
+ readonly tags: readonly string[];
278
+ readonly title: string;
279
+ readonly url: string;
280
+ }[];
281
+ };
282
+ };
283
+ }, {
284
+ readonly resources: {
285
+ readonly results: {
286
+ readonly queries?: readonly {
287
+ readonly url: string;
288
+ readonly text: string;
289
+ readonly styled_text: string;
290
+ }[] | undefined;
291
+ readonly products?: readonly {
292
+ readonly body: string;
293
+ readonly title: string;
294
+ readonly vendor: string | null;
295
+ readonly url: string;
296
+ readonly image: string | null;
297
+ readonly available: boolean;
298
+ readonly id: string | number;
299
+ readonly price: string;
300
+ readonly featured_image: {
301
+ readonly aspect_ratio: number | null;
302
+ readonly alt: string | null;
303
+ readonly height: number | null;
304
+ readonly url: string | null;
305
+ readonly width: number | null;
306
+ };
307
+ readonly variants: readonly {
308
+ readonly available: boolean;
309
+ readonly compare_at_price: string | null;
310
+ readonly id: string | number;
311
+ readonly image: string | null;
312
+ readonly price: string;
119
313
  readonly title: string;
120
314
  readonly url: string;
121
- readonly id: string | number;
122
315
  readonly featured_image: {
123
316
  readonly aspect_ratio: number | null;
124
317
  readonly alt: string | null;
@@ -126,37 +319,52 @@ export declare const get: (input?: ({
126
319
  readonly url: string | null;
127
320
  readonly width: number | null;
128
321
  };
129
- readonly handle: string;
130
- readonly published_at: Date;
131
- }[];
132
- readonly pages: readonly {
133
- readonly author: string;
134
- readonly body: string;
135
- readonly title: string;
136
- readonly url: string;
137
- readonly id: string | number;
138
- readonly handle: string;
139
- readonly published_at: Date;
140
322
  }[];
141
- readonly articles: readonly {
142
- readonly author: string;
143
- readonly body: string;
144
- readonly title: string;
145
- readonly url: string;
146
- readonly id: string | number;
147
- readonly handle: string;
148
- readonly tags: readonly string[];
149
- readonly published_at: Date;
150
- readonly summary_html: string;
151
- }[];
152
- };
323
+ readonly compare_at_price_max: string;
324
+ readonly compare_at_price_min: string;
325
+ readonly handle: string;
326
+ readonly price_max: string;
327
+ readonly price_min: string;
328
+ readonly type: string;
329
+ readonly tags?: readonly string[] | undefined;
330
+ }[] | undefined;
331
+ readonly collections?: readonly {
332
+ readonly body: string;
333
+ readonly handle: string;
334
+ readonly id: string | number;
335
+ readonly featured_image: {
336
+ readonly aspect_ratio: number | null;
337
+ readonly alt: string | null;
338
+ readonly height: number | null;
339
+ readonly url: string | null;
340
+ readonly width: number | null;
341
+ };
342
+ readonly published_at: string;
343
+ readonly title: string;
344
+ readonly url: string;
345
+ }[] | undefined;
346
+ readonly pages?: readonly {
347
+ readonly author: string;
348
+ readonly body: string;
349
+ readonly handle: string;
350
+ readonly id: string | number;
351
+ readonly published_at: string;
352
+ readonly title: string;
353
+ readonly url: string;
354
+ }[] | undefined;
355
+ readonly articles?: readonly {
356
+ readonly author: string;
357
+ readonly body: string;
358
+ readonly title: string;
359
+ readonly url: string;
360
+ readonly id: string | number;
361
+ readonly handle: string;
362
+ readonly published_at: string;
363
+ readonly summary_html: string;
364
+ readonly tags?: readonly string[] | undefined;
365
+ }[] | undefined;
153
366
  };
154
- } | undefined;
155
- readonly error?: {
156
- status: number;
157
- message: string;
158
- description?: string;
159
- } | undefined;
160
- }, Error, import("@effect/platform/HttpClient").HttpClient>;
367
+ };
368
+ }, never>;
161
369
 
162
370
  export {};
@@ -1,12 +1,14 @@
1
- import * as AjaxClient from '@brytdesigns/shopify-ajax-client';
2
- import { Output, Input } from './schema';
3
-
4
- const get = AjaxClient.makeFactory({
5
- routeName: "predictive_search_url",
6
- inputSchema: Input,
7
- outputSchema: Output
1
+ import { Input, Output } from "./schema.js";
2
+ import * as AjaxClient from "@brytdesigns/shopify-ajax-client";
3
+ import { Ajax } from "@brytdesigns/shopify-utils/effect";
4
+ import * as Schema from "effect/Schema";
5
+ //#region src/effect/index.ts
6
+ var get = AjaxClient.makeRoute({
7
+ routeName: "predictive_search_url",
8
+ inputSchema: Input,
9
+ outputSchema: (sections) => sections === void 0 ? Output : Output.pipe(Schema.fieldsAssign({ sections: Ajax.Sections.makeResponseSchema(sections) }))
8
10
  });
9
-
11
+ //#endregion
10
12
  export { get };
11
- //# sourceMappingURL=index.js.map
13
+
12
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/effect/index.ts"],"names":[],"mappings":";;;AAMa,MAAA,GAAA,GAAM,WAAW,WAAY,CAAA;AAAA,EACxC,SAAW,EAAA,uBAAA;AAAA,EACX,WAAa,EAAA,KAAA;AAAA,EACb,YAAc,EAAA;AAChB,CAAC","file":"index.js","sourcesContent":["import * as AjaxClient from \"@brytdesigns/shopify-ajax-client\";\nimport { type Input as _Input, Input, Output } from \"./schema\";\n\nexport namespace get {\n export type Input = _Input;\n}\nexport const get = AjaxClient.makeFactory({\n routeName: \"predictive_search_url\",\n inputSchema: Input,\n outputSchema: Output,\n});\n"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/effect/index.ts"],"sourcesContent":["import * as AjaxClient from \"@brytdesigns/shopify-ajax-client\";\nimport { Ajax } from \"@brytdesigns/shopify-utils/effect\";\nimport * as Schema from \"effect/Schema\";\nimport { type Input as _Input, Input, Output } from \"./schema\";\n\nexport namespace get {\n\texport type Input = _Input;\n}\n\nexport const get = AjaxClient.makeRoute({\n\trouteName: \"predictive_search_url\",\n\tinputSchema: Input,\n\t// Composed here rather than inside makeRoute: v4 can only extend a Struct,\n\t// and Output is one, so the caller is the right place to add the field.\n\toutputSchema: (sections?: string) =>\n\t\tsections === undefined\n\t\t\t? Output\n\t\t\t: Output.pipe(\n\t\t\t\t\tSchema.fieldsAssign({\n\t\t\t\t\t\tsections: Ajax.Sections.makeResponseSchema(sections),\n\t\t\t\t\t}),\n\t\t\t\t),\n});\n"],"mappings":";;;;;AASA,IAAa,MAAM,WAAW,UAAU;CACvC,WAAW;CACX,aAAa;CAGb,eAAe,aACd,aAAa,KAAA,IACV,SACA,OAAO,KACP,OAAO,aAAa,EACnB,UAAU,KAAK,SAAS,mBAAmB,QAAQ,EACpD,CAAC,CACF;AACJ,CAAC"}