@tallyui/connector-shopify 3.10.0 → 3.12.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/index.js +43 -51
- package/package.json +2 -2
- package/src/replication/products.ts +2 -2
- package/src/sync/products.ts +1 -17
package/dist/index.js
CHANGED
|
@@ -160,6 +160,49 @@ var shopifyProductTraits = {
|
|
|
160
160
|
getCategories: (doc) => doc.product_type ? [{ id: doc.product_type, name: doc.product_type }] : []
|
|
161
161
|
};
|
|
162
162
|
|
|
163
|
+
// src/replication/products.ts
|
|
164
|
+
function parseLinkNext(linkHeader) {
|
|
165
|
+
if (!linkHeader) return "";
|
|
166
|
+
const match = linkHeader.match(/<([^>]+)>;\s*rel="next"/);
|
|
167
|
+
return match ? match[1] : "";
|
|
168
|
+
}
|
|
169
|
+
function normalizeId(product) {
|
|
170
|
+
return { ...product, id: String(product.id) };
|
|
171
|
+
}
|
|
172
|
+
var shopifyProductReplication = {
|
|
173
|
+
pull: {
|
|
174
|
+
async handler(lastCheckpoint, batchSize, context) {
|
|
175
|
+
const params = new URLSearchParams({
|
|
176
|
+
limit: String(batchSize)
|
|
177
|
+
});
|
|
178
|
+
if (lastCheckpoint?.updated_at) {
|
|
179
|
+
params.set("updated_at_min", lastCheckpoint.updated_at);
|
|
180
|
+
}
|
|
181
|
+
let url = `${context.baseUrl}/admin/api/2024-01/products.json?${params}`;
|
|
182
|
+
const allProducts = [];
|
|
183
|
+
while (url) {
|
|
184
|
+
const response = await fetch(url, {
|
|
185
|
+
headers: {
|
|
186
|
+
...context.headers,
|
|
187
|
+
"Content-Type": "application/json"
|
|
188
|
+
},
|
|
189
|
+
signal: context.signal
|
|
190
|
+
});
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
throw new Error(`Shopify API error: ${response.status}`);
|
|
193
|
+
}
|
|
194
|
+
const data = await response.json();
|
|
195
|
+
const products = (data.products ?? []).map(normalizeId);
|
|
196
|
+
allProducts.push(...products);
|
|
197
|
+
url = parseLinkNext(response.headers.get("Link"));
|
|
198
|
+
}
|
|
199
|
+
const documents = allProducts.map((p) => ({ ...p, _deleted: false }));
|
|
200
|
+
const checkpoint = allProducts.length > 0 ? { updated_at: allProducts[allProducts.length - 1].updated_at } : lastCheckpoint ?? { updated_at: "" };
|
|
201
|
+
return { documents, checkpoint };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
163
206
|
// src/sync/products.ts
|
|
164
207
|
var shopifyProductSync = {
|
|
165
208
|
fetchAllIds: async (context) => {
|
|
@@ -211,57 +254,6 @@ var shopifyProductSync = {
|
|
|
211
254
|
return products;
|
|
212
255
|
}
|
|
213
256
|
};
|
|
214
|
-
function normalizeId(product) {
|
|
215
|
-
return { ...product, id: String(product.id) };
|
|
216
|
-
}
|
|
217
|
-
function parseLinkNext(linkHeader) {
|
|
218
|
-
if (!linkHeader) return "";
|
|
219
|
-
const match = linkHeader.match(/<([^>]+)>;\s*rel="next"/);
|
|
220
|
-
return match ? match[1] : "";
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// src/replication/products.ts
|
|
224
|
-
function parseLinkNext2(linkHeader) {
|
|
225
|
-
if (!linkHeader) return "";
|
|
226
|
-
const match = linkHeader.match(/<([^>]+)>;\s*rel="next"/);
|
|
227
|
-
return match ? match[1] : "";
|
|
228
|
-
}
|
|
229
|
-
function normalizeId2(product) {
|
|
230
|
-
return { ...product, id: String(product.id) };
|
|
231
|
-
}
|
|
232
|
-
var shopifyProductReplication = {
|
|
233
|
-
pull: {
|
|
234
|
-
async handler(lastCheckpoint, batchSize, context) {
|
|
235
|
-
const params = new URLSearchParams({
|
|
236
|
-
limit: String(batchSize)
|
|
237
|
-
});
|
|
238
|
-
if (lastCheckpoint?.updated_at) {
|
|
239
|
-
params.set("updated_at_min", lastCheckpoint.updated_at);
|
|
240
|
-
}
|
|
241
|
-
let url = `${context.baseUrl}/admin/api/2024-01/products.json?${params}`;
|
|
242
|
-
const allProducts = [];
|
|
243
|
-
while (url) {
|
|
244
|
-
const response = await fetch(url, {
|
|
245
|
-
headers: {
|
|
246
|
-
...context.headers,
|
|
247
|
-
"Content-Type": "application/json"
|
|
248
|
-
},
|
|
249
|
-
signal: context.signal
|
|
250
|
-
});
|
|
251
|
-
if (!response.ok) {
|
|
252
|
-
throw new Error(`Shopify API error: ${response.status}`);
|
|
253
|
-
}
|
|
254
|
-
const data = await response.json();
|
|
255
|
-
const products = (data.products ?? []).map(normalizeId2);
|
|
256
|
-
allProducts.push(...products);
|
|
257
|
-
url = parseLinkNext2(response.headers.get("Link"));
|
|
258
|
-
}
|
|
259
|
-
const documents = allProducts.map((p) => ({ ...p, _deleted: false }));
|
|
260
|
-
const checkpoint = allProducts.length > 0 ? { updated_at: allProducts[allProducts.length - 1].updated_at } : lastCheckpoint ?? { updated_at: "" };
|
|
261
|
-
return { documents, checkpoint };
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
257
|
|
|
266
258
|
// src/index.ts
|
|
267
259
|
var shopifyConnector = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/connector-shopify",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shopify connector for Tally UI",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"directory": "connectors/shopify"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@tallyui/core": "^3.
|
|
29
|
+
"@tallyui/core": "^3.12.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"rxdb": "17.5.0"
|
|
@@ -8,7 +8,7 @@ export type ShopifyProductCheckpoint = {
|
|
|
8
8
|
* Parse the "next" URL from Shopify's Link header for cursor pagination.
|
|
9
9
|
* Returns an empty string if there's no next page.
|
|
10
10
|
*/
|
|
11
|
-
function parseLinkNext(linkHeader: string | null): string {
|
|
11
|
+
export function parseLinkNext(linkHeader: string | null): string {
|
|
12
12
|
if (!linkHeader) return '';
|
|
13
13
|
const match = linkHeader.match(/<([^>]+)>;\s*rel="next"/);
|
|
14
14
|
return match ? match[1] : '';
|
|
@@ -17,7 +17,7 @@ function parseLinkNext(linkHeader: string | null): string {
|
|
|
17
17
|
/**
|
|
18
18
|
* Shopify IDs are integers but RxDB primary keys must be strings.
|
|
19
19
|
*/
|
|
20
|
-
function normalizeId(product: any) {
|
|
20
|
+
export function normalizeId(product: any) {
|
|
21
21
|
return { ...product, id: String(product.id) };
|
|
22
22
|
}
|
|
23
23
|
|
package/src/sync/products.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CollectionSync, SyncContext } from '@tallyui/core';
|
|
2
|
+
import { normalizeId, parseLinkNext } from '../replication/products';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Shopify product sync implementation.
|
|
@@ -72,20 +73,3 @@ export const shopifyProductSync: CollectionSync = {
|
|
|
72
73
|
return products;
|
|
73
74
|
},
|
|
74
75
|
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Shopify IDs are integers but RxDB primary keys must be strings.
|
|
78
|
-
*/
|
|
79
|
-
function normalizeId(product: any) {
|
|
80
|
-
return { ...product, id: String(product.id) };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Parse the "next" URL from Shopify's Link header for cursor pagination.
|
|
85
|
-
* Returns null if there's no next page.
|
|
86
|
-
*/
|
|
87
|
-
function parseLinkNext(linkHeader: string | null): string {
|
|
88
|
-
if (!linkHeader) return '';
|
|
89
|
-
const match = linkHeader.match(/<([^>]+)>;\s*rel="next"/);
|
|
90
|
-
return match ? match[1] : '';
|
|
91
|
-
}
|