@frontstackdev/cli 0.0.0-canary-20250318182507 → 0.0.0-canary-20250318230714
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,28 +60,21 @@ 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: [] }
|
|
86
74
|
*/
|
|
87
75
|
page: (
|
|
88
76
|
slug: string | string[],
|
|
89
|
-
config?:
|
|
90
|
-
options?: RequestOptions
|
|
91
|
-
}
|
|
77
|
+
config?: RequestOptions
|
|
92
78
|
) => Promise<Page>;
|
|
93
79
|
|
|
94
80
|
/**
|
|
@@ -131,7 +117,7 @@ export interface FrontstackClient {
|
|
|
131
117
|
) => Promise<Context>;
|
|
132
118
|
}
|
|
133
119
|
|
|
134
|
-
const endpoints:
|
|
120
|
+
const endpoints: Endpoints = {
|
|
135
121
|
{{#each paths}}
|
|
136
122
|
{{#if (endsWith this.post.operationId "Block")}}
|
|
137
123
|
{{this.summary}}: '{{@key}}',
|
|
@@ -178,10 +164,10 @@ const servers = {
|
|
|
178
164
|
*/
|
|
179
165
|
const client: FrontstackClient = {
|
|
180
166
|
/**
|
|
181
|
-
* Fetch a
|
|
167
|
+
* Fetch a block with a key
|
|
182
168
|
*/
|
|
183
|
-
block: async (
|
|
184
|
-
let endpoint: string = `${servers[0].url}${endpoints[
|
|
169
|
+
block: async (name, key, config) => {
|
|
170
|
+
let endpoint: string = `${servers[0].url}${endpoints[name]}`;
|
|
185
171
|
|
|
186
172
|
// Replace '{key}' in the endpoint
|
|
187
173
|
endpoint = endpoint.replace('{key}', key);
|
|
@@ -191,32 +177,32 @@ const client: FrontstackClient = {
|
|
|
191
177
|
|
|
192
178
|
let headers: Record<string, string> = {}
|
|
193
179
|
|
|
194
|
-
if(config?.
|
|
195
|
-
headers['fs-request-url'] = config.
|
|
180
|
+
if(config?.requestUrl !== undefined) {
|
|
181
|
+
headers['fs-request-url'] = config.requestUrl
|
|
196
182
|
}
|
|
197
|
-
if (config?.
|
|
198
|
-
headers["fs-token"] = config.
|
|
183
|
+
if (config?.contextKey !== undefined) {
|
|
184
|
+
headers["fs-token"] = config.contextKey;
|
|
199
185
|
}
|
|
200
186
|
|
|
201
187
|
return (await invoke(endpoint, 'POST', payload, headers))._data
|
|
202
188
|
},
|
|
203
189
|
|
|
204
190
|
/**
|
|
205
|
-
* Fetch a listing
|
|
191
|
+
* Fetch a listing with parameters and optional query filters
|
|
206
192
|
*/
|
|
207
|
-
listing: async (
|
|
208
|
-
let endpoint: string = `${servers[0].url}${endpoints[
|
|
193
|
+
listing: async (name, parameters, config) => {
|
|
194
|
+
let endpoint: string = `${servers[0].url}${endpoints[name]}`;
|
|
209
195
|
|
|
210
|
-
// Merge
|
|
196
|
+
// Merge listing parameters with query
|
|
211
197
|
let payload = config && 'query' in config ? { param: {...parameters}, ...config.query } : { param: {...parameters} }
|
|
212
198
|
|
|
213
199
|
let headers: Record<string, string> = {}
|
|
214
200
|
|
|
215
|
-
if(config?.
|
|
216
|
-
headers['fs-request-url'] = config.
|
|
201
|
+
if(config?.requestUrl !== undefined) {
|
|
202
|
+
headers['fs-request-url'] = config.requestUrl
|
|
217
203
|
}
|
|
218
|
-
if (config?.
|
|
219
|
-
headers["fs-token"] = config.
|
|
204
|
+
if (config?.contextKey !== undefined) {
|
|
205
|
+
headers["fs-token"] = config.contextKey;
|
|
220
206
|
}
|
|
221
207
|
|
|
222
208
|
return (await invoke(endpoint, 'POST', payload, headers))._data
|
|
@@ -230,11 +216,11 @@ const client: FrontstackClient = {
|
|
|
230
216
|
|
|
231
217
|
let headers: Record<string, string> = {}
|
|
232
218
|
|
|
233
|
-
if(config?.
|
|
234
|
-
headers['fs-request-url'] = config.
|
|
219
|
+
if(config?.requestUrl !== undefined) {
|
|
220
|
+
headers['fs-request-url'] = config.requestUrl
|
|
235
221
|
}
|
|
236
|
-
if (config?.
|
|
237
|
-
headers["fs-token"] = config.
|
|
222
|
+
if (config?.contextKey !== undefined) {
|
|
223
|
+
headers["fs-token"] = config.contextKey;
|
|
238
224
|
}
|
|
239
225
|
|
|
240
226
|
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-20250318230714
|