@frontstackdev/cli 0.0.0-canary-20250318182507 → 0.0.0-canary-20250318195346
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.
|
@@ -4,43 +4,36 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { ofetch } from 'ofetch'
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
import type { Endpoints, Responses, RequestOptions, Page, Blocks, Listings, ListingParameters, ListingQueryFilters, ListingQuerySorts } from './generated-types'
|
|
9
|
+
|
|
8
10
|
import type { Query } from './query-types'
|
|
9
11
|
|
|
10
12
|
type Method = 'GET' | 'POST' | 'PATCH' | 'DELETE'
|
|
11
|
-
type ContextToken = string
|
|
12
|
-
type Context = any
|
|
13
|
-
type ContextOption = any
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Interface describing the frontstack client API
|
|
17
16
|
*/
|
|
18
17
|
export interface FrontstackClient {
|
|
19
18
|
/**
|
|
20
|
-
* Fetch a
|
|
19
|
+
* Fetch a block with a key
|
|
21
20
|
*
|
|
22
|
-
* @param
|
|
21
|
+
* @param name The name of the block to fetch
|
|
23
22
|
* @example 'VariantCard'
|
|
24
23
|
* @param key The key identifier for the block
|
|
25
24
|
* @example '<variant-id>'
|
|
26
25
|
* @param config Further configuration options
|
|
27
26
|
*/
|
|
28
|
-
block: <
|
|
29
|
-
|
|
27
|
+
block: <ApiName extends keyof Blocks>(
|
|
28
|
+
name: ApiName,
|
|
30
29
|
key: string,
|
|
31
|
-
config?:
|
|
32
|
-
|
|
33
|
-
* Additional configuration options:
|
|
34
|
-
* - `requestUrl` to provide a URL that will be used to track the origin of the request
|
|
35
|
-
*/
|
|
36
|
-
options?: RequestOptions
|
|
37
|
-
}
|
|
38
|
-
) => Promise<BlockResponses[BlockName]>;
|
|
30
|
+
config?: RequestOptions
|
|
31
|
+
) => Promise<Responses[ApiName]>;
|
|
39
32
|
|
|
40
33
|
/**
|
|
41
|
-
* Fetch a listing
|
|
34
|
+
* Fetch a listing with optional parameters and query filters
|
|
42
35
|
*
|
|
43
|
-
* @param
|
|
36
|
+
* @param name The name of the listing to fetch
|
|
44
37
|
* @example 'ProductList'
|
|
45
38
|
* @param parameters The parameters to pass to the listing
|
|
46
39
|
* @example { categoryId: '<category-id>' }
|
|
@@ -55,9 +48,9 @@ export interface FrontstackClient {
|
|
|
55
48
|
* }
|
|
56
49
|
* }
|
|
57
50
|
*/
|
|
58
|
-
listing: <
|
|
59
|
-
|
|
60
|
-
parameters:
|
|
51
|
+
listing: <ApiName extends keyof Listings>(
|
|
52
|
+
name: ApiName,
|
|
53
|
+
parameters: ListingParameters[ApiName],
|
|
61
54
|
config?: {
|
|
62
55
|
/**
|
|
63
56
|
* Query parameters to pass to the listing:
|
|
@@ -67,19 +60,14 @@ export interface FrontstackClient {
|
|
|
67
60
|
* - `limit` to limit the number of results returned
|
|
68
61
|
* - `page` to paginate results
|
|
69
62
|
*/
|
|
70
|
-
query?: Query<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* - `requestUrl` to provide a URL that will be used to track the origin of the request
|
|
74
|
-
*/
|
|
75
|
-
options?: RequestOptions
|
|
76
|
-
}
|
|
77
|
-
) => Promise<BlockResponses[BlockName]>;
|
|
63
|
+
query?: Query<ListingQueryFilters[ApiName], ListingQuerySorts[ApiName]>
|
|
64
|
+
} | RequestOptions
|
|
65
|
+
) => Promise<Responses[ApiName]>;
|
|
78
66
|
|
|
79
67
|
/**
|
|
80
68
|
* Fetch a page by its slug
|
|
81
69
|
* @param slug The URL slug of the page (without protocol)
|
|
82
|
-
* @example
|
|
70
|
+
* @example demo-shop.com/uk/women/shoes/running
|
|
83
71
|
*
|
|
84
72
|
* @returns The page data
|
|
85
73
|
* @example { data: { title: 'Running Shoes' }, type: 'ProductCategory', urls: [] }
|
|
@@ -131,7 +119,7 @@ export interface FrontstackClient {
|
|
|
131
119
|
) => Promise<Context>;
|
|
132
120
|
}
|
|
133
121
|
|
|
134
|
-
const endpoints:
|
|
122
|
+
const endpoints: Endpoints = {
|
|
135
123
|
{{#each paths}}
|
|
136
124
|
{{#if (endsWith this.post.operationId "Block")}}
|
|
137
125
|
{{this.summary}}: '{{@key}}',
|
|
@@ -178,10 +166,10 @@ const servers = {
|
|
|
178
166
|
*/
|
|
179
167
|
const client: FrontstackClient = {
|
|
180
168
|
/**
|
|
181
|
-
* Fetch a
|
|
169
|
+
* Fetch a block with a key
|
|
182
170
|
*/
|
|
183
|
-
block: async (
|
|
184
|
-
let endpoint: string = `${servers[0].url}${endpoints[
|
|
171
|
+
block: async (name, key, config) => {
|
|
172
|
+
let endpoint: string = `${servers[0].url}${endpoints[name]}`;
|
|
185
173
|
|
|
186
174
|
// Replace '{key}' in the endpoint
|
|
187
175
|
endpoint = endpoint.replace('{key}', key);
|
|
@@ -191,32 +179,32 @@ const client: FrontstackClient = {
|
|
|
191
179
|
|
|
192
180
|
let headers: Record<string, string> = {}
|
|
193
181
|
|
|
194
|
-
if(config?.
|
|
195
|
-
headers['fs-request-url'] = config.
|
|
182
|
+
if(config?.requestUrl !== undefined) {
|
|
183
|
+
headers['fs-request-url'] = config.requestUrl
|
|
196
184
|
}
|
|
197
|
-
if (config?.
|
|
198
|
-
headers["fs-token"] = config.
|
|
185
|
+
if (config?.contextKey !== undefined) {
|
|
186
|
+
headers["fs-token"] = config.contextKey;
|
|
199
187
|
}
|
|
200
188
|
|
|
201
189
|
return (await invoke(endpoint, 'POST', payload, headers))._data
|
|
202
190
|
},
|
|
203
191
|
|
|
204
192
|
/**
|
|
205
|
-
* Fetch a listing
|
|
193
|
+
* Fetch a listing with parameters and optional query filters
|
|
206
194
|
*/
|
|
207
|
-
listing: async (
|
|
208
|
-
let endpoint: string = `${servers[0].url}${endpoints[
|
|
195
|
+
listing: async (name, parameters, config) => {
|
|
196
|
+
let endpoint: string = `${servers[0].url}${endpoints[name]}`;
|
|
209
197
|
|
|
210
|
-
// Merge
|
|
198
|
+
// Merge listing parameters with query
|
|
211
199
|
let payload = config && 'query' in config ? { param: {...parameters}, ...config.query } : { param: {...parameters} }
|
|
212
200
|
|
|
213
201
|
let headers: Record<string, string> = {}
|
|
214
202
|
|
|
215
|
-
if(config?.
|
|
216
|
-
headers['fs-request-url'] = config.
|
|
203
|
+
if(config?.requestUrl !== undefined) {
|
|
204
|
+
headers['fs-request-url'] = config.requestUrl
|
|
217
205
|
}
|
|
218
|
-
if (config?.
|
|
219
|
-
headers["fs-token"] = config.
|
|
206
|
+
if (config?.contextKey !== undefined) {
|
|
207
|
+
headers["fs-token"] = config.contextKey;
|
|
220
208
|
}
|
|
221
209
|
|
|
222
210
|
return (await invoke(endpoint, 'POST', payload, headers))._data
|
|
@@ -230,11 +218,11 @@ const client: FrontstackClient = {
|
|
|
230
218
|
|
|
231
219
|
let headers: Record<string, string> = {}
|
|
232
220
|
|
|
233
|
-
if(config?.
|
|
234
|
-
headers['fs-request-url'] = config.
|
|
221
|
+
if(config?.requestUrl !== undefined) {
|
|
222
|
+
headers['fs-request-url'] = config.requestUrl
|
|
235
223
|
}
|
|
236
|
-
if (config?.
|
|
237
|
-
headers["fs-token"] = config.
|
|
224
|
+
if (config?.contextKey !== undefined) {
|
|
225
|
+
headers["fs-token"] = config.contextKey;
|
|
238
226
|
}
|
|
239
227
|
|
|
240
228
|
return (await invoke(endpoint, 'GET', null, headers))._data
|
|
@@ -23,7 +23,7 @@ type RequestOptions = {
|
|
|
23
23
|
|
|
24
24
|
/* List of all types used to fetch block parameters */
|
|
25
25
|
|
|
26
|
-
{{#each paths}}{{#if (and (endsWith this.post.operationId "Block") (contains this.post.tags "
|
|
26
|
+
{{#each paths}}{{#if (and (endsWith this.post.operationId "Block") (contains this.post.tags "fetch-listing"))}}export type {{this.summary}}Parameters = {
|
|
27
27
|
{{#each this.post.parameters}}
|
|
28
28
|
{{#if @first}}{{else}}
|
|
29
29
|
{{/if}}
|
|
@@ -49,30 +49,30 @@ type RequestOptions = {
|
|
|
49
49
|
{{/if}}{{/each}}
|
|
50
50
|
/* List of all blocks, used for IDE autocompletion */
|
|
51
51
|
|
|
52
|
-
type
|
|
52
|
+
type ListingParameters = {
|
|
53
53
|
{{#each components.schemas}}
|
|
54
|
-
{{#if (contains tags "
|
|
54
|
+
{{#if (contains tags "fetch-listing")}}
|
|
55
55
|
{{@key}}: {{@key}}Parameters
|
|
56
56
|
{{/if}}
|
|
57
57
|
{{/each}}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
type
|
|
61
|
-
[key in keyof
|
|
60
|
+
type Endpoints = {
|
|
61
|
+
[key in keyof Listings | keyof Blocks]: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/* Types for split block/listing methods */
|
|
65
|
-
export type
|
|
65
|
+
export type Blocks = {
|
|
66
66
|
{{#each components.schemas}}
|
|
67
|
-
{{#if (contains tags "
|
|
67
|
+
{{#if (contains tags "fetch-block")}}
|
|
68
68
|
{{@key}}: never
|
|
69
69
|
{{/if}}
|
|
70
70
|
{{/each}}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
export type
|
|
73
|
+
export type Listings = {
|
|
74
74
|
{{#each components.schemas}}
|
|
75
|
-
{{#if (contains tags "
|
|
75
|
+
{{#if (contains tags "fetch-listing")}}
|
|
76
76
|
{{@key}}: {{@key}}Parameters
|
|
77
77
|
{{/if}}
|
|
78
78
|
{{/each}}
|
|
@@ -80,40 +80,40 @@ export type QueryBlocks = {
|
|
|
80
80
|
|
|
81
81
|
declare global {
|
|
82
82
|
{{#each components.schemas}}
|
|
83
|
-
{{#if (contains tags "
|
|
83
|
+
{{#if (contains tags "fetch-api")}}
|
|
84
84
|
export type {{@key}} = components['schemas']['{{@key}}']
|
|
85
85
|
{{/if}}
|
|
86
86
|
{{/each}}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export type
|
|
89
|
+
export type Responses = {
|
|
90
90
|
{{#each components.schemas}}
|
|
91
|
-
{{#if (contains tags "
|
|
91
|
+
{{#if (contains tags "fetch-api")}}
|
|
92
92
|
{{@key}}: {{@key}}
|
|
93
93
|
{{/if}}
|
|
94
94
|
{{/each}}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export type
|
|
97
|
+
export type ListingQueryFilters = {
|
|
98
98
|
{{#each components.schemas}}
|
|
99
|
-
{{#if (contains tags "
|
|
99
|
+
{{#if (contains tags "fetch-listing")}}
|
|
100
100
|
{{@key}}: components['schemas']['{{@key}}QueryOptions']['filter']
|
|
101
101
|
{{/if}}
|
|
102
102
|
{{/each}}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export type
|
|
105
|
+
export type ListingQuerySorts = {
|
|
106
106
|
{{#each components.schemas}}
|
|
107
|
-
{{#if (contains tags "
|
|
107
|
+
{{#if (contains tags "fetch-listing")}}
|
|
108
108
|
{{@key}}: components['schemas']['{{@key}}QueryOptions']['sort']
|
|
109
109
|
{{/if}}
|
|
110
110
|
{{/each}}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
type
|
|
113
|
+
type FetchMode = {
|
|
114
114
|
{{#each components.schemas}}
|
|
115
|
-
{{#if (contains tags "
|
|
116
|
-
{{@key}}: {{#if (contains tags "
|
|
115
|
+
{{#if (contains tags "fetch-api")}}
|
|
116
|
+
{{@key}}: {{#if (contains tags "fetch-listing") }}'query'{{else}}'key'{{/if}};
|
|
117
117
|
{{/if}}
|
|
118
118
|
{{/each}}
|
|
119
119
|
}
|
package/dist/version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.0-canary-
|
|
1
|
+
0.0.0-canary-20250318195346
|