@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
- import type { BlockEndpoints, BlockParameters, BlockResponses, RequestOptions, BlockQueryFilters, BlockQuerySorts, BlockMode, Page, KeyBlocks, QueryBlocks } from './generated-types'
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 simple block with a key
19
+ * Fetch a block with a key
21
20
  *
22
- * @param blockName The name of the block to fetch
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: <BlockName extends keyof KeyBlocks>(
29
- blockName: BlockName,
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 block with parameters and optional query filters
34
+ * Fetch a listing with optional parameters and query filters
42
35
  *
43
- * @param blockName The name of the listing block to fetch
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: <BlockName extends keyof QueryBlocks>(
59
- blockName: BlockName,
60
- parameters: BlockParameters[BlockName],
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<BlockQueryFilters[BlockName], BlockQuerySorts[BlockName]>
71
- /**
72
- * Additional configuration options:
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 my-brand.com/uk/women/shoes/running
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: BlockEndpoints = {
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 simple block with a key
169
+ * Fetch a block with a key
182
170
  */
183
- block: async (blockName, key, config) => {
184
- let endpoint: string = `${servers[0].url}${endpoints[blockName]}`;
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?.options?.requestUrl !== undefined) {
195
- headers['fs-request-url'] = config.options.requestUrl
182
+ if(config?.requestUrl !== undefined) {
183
+ headers['fs-request-url'] = config.requestUrl
196
184
  }
197
- if (config?.options?.contextKey !== undefined) {
198
- headers["fs-token"] = config.options.contextKey;
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 block with parameters and optional query filters
193
+ * Fetch a listing with parameters and optional query filters
206
194
  */
207
- listing: async (blockName, parameters, config) => {
208
- let endpoint: string = `${servers[0].url}${endpoints[blockName]}`;
195
+ listing: async (name, parameters, config) => {
196
+ let endpoint: string = `${servers[0].url}${endpoints[name]}`;
209
197
 
210
- // Merge block parameters with query
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?.options?.requestUrl !== undefined) {
216
- headers['fs-request-url'] = config.options.requestUrl
203
+ if(config?.requestUrl !== undefined) {
204
+ headers['fs-request-url'] = config.requestUrl
217
205
  }
218
- if (config?.options?.contextKey !== undefined) {
219
- headers["fs-token"] = config.options.contextKey;
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?.options?.requestUrl !== undefined) {
234
- headers['fs-request-url'] = config.options.requestUrl
221
+ if(config?.requestUrl !== undefined) {
222
+ headers['fs-request-url'] = config.requestUrl
235
223
  }
236
- if (config?.options?.contextKey !== undefined) {
237
- headers["fs-token"] = config.options.contextKey;
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 "query-block"))}}export type {{this.summary}}Parameters = {
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 BlockParameters = {
52
+ type ListingParameters = {
53
53
  {{#each components.schemas}}
54
- {{#if (contains tags "query-block")}}
54
+ {{#if (contains tags "fetch-listing")}}
55
55
  {{@key}}: {{@key}}Parameters
56
56
  {{/if}}
57
57
  {{/each}}
58
58
  }
59
59
 
60
- type BlockEndpoints = {
61
- [key in keyof QueryBlocks | keyof KeyBlocks]: string;
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 KeyBlocks = {
65
+ export type Blocks = {
66
66
  {{#each components.schemas}}
67
- {{#if (contains tags "key-block")}}
67
+ {{#if (contains tags "fetch-block")}}
68
68
  {{@key}}: never
69
69
  {{/if}}
70
70
  {{/each}}
71
71
  }
72
72
 
73
- export type QueryBlocks = {
73
+ export type Listings = {
74
74
  {{#each components.schemas}}
75
- {{#if (contains tags "query-block")}}
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 "blocks")}}
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 BlockResponses = {
89
+ export type Responses = {
90
90
  {{#each components.schemas}}
91
- {{#if (contains tags "blocks")}}
91
+ {{#if (contains tags "fetch-api")}}
92
92
  {{@key}}: {{@key}}
93
93
  {{/if}}
94
94
  {{/each}}
95
95
  }
96
96
 
97
- export type BlockQueryFilters = {
97
+ export type ListingQueryFilters = {
98
98
  {{#each components.schemas}}
99
- {{#if (contains tags "query-block")}}
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 BlockQuerySorts = {
105
+ export type ListingQuerySorts = {
106
106
  {{#each components.schemas}}
107
- {{#if (contains tags "query-block")}}
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 BlockMode = {
113
+ type FetchMode = {
114
114
  {{#each components.schemas}}
115
- {{#if (contains tags "blocks")}}
116
- {{@key}}: {{#if (contains tags "query-block") }}'query'{{else}}'key'{{/if}};
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-20250318182507
1
+ 0.0.0-canary-20250318195346
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontstackdev/cli",
3
- "version": "0.0.0-canary-20250318182507",
3
+ "version": "0.0.0-canary-20250318195346",
4
4
  "description": "frontstack CLI for managing projects",
5
5
  "type": "module",
6
6
  "module": "dist/frontstack.mjs",