feeef 0.7.5 → 0.8.1

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/build/index.js CHANGED
@@ -1494,6 +1494,373 @@ var ProductLandingPagesRepository = class extends ModelRepository {
1494
1494
  }
1495
1495
  };
1496
1496
 
1497
+ // src/core/entities/attachment.ts
1498
+ var ATTACHMENT_TYPES = ["image", "url", "audio", "product", "store"];
1499
+ function asRecord(value) {
1500
+ if (value && typeof value === "object" && !Array.isArray(value)) {
1501
+ return value;
1502
+ }
1503
+ return {};
1504
+ }
1505
+ function nullableTrimmedString(value) {
1506
+ if (value === null) return null;
1507
+ if (value === void 0) return void 0;
1508
+ const normalized = String(value).trim();
1509
+ return normalized.length > 0 ? normalized : void 0;
1510
+ }
1511
+ function isAttachmentType(value) {
1512
+ return typeof value === "string" && ATTACHMENT_TYPES.includes(value);
1513
+ }
1514
+ function normalizeAttachmentPayload(value) {
1515
+ const record = asRecord(value);
1516
+ const type = record.type;
1517
+ const normalizedValue = nullableTrimmedString(record.value);
1518
+ if (!isAttachmentType(type) || !normalizedValue) {
1519
+ return null;
1520
+ }
1521
+ return {
1522
+ type,
1523
+ value: normalizedValue,
1524
+ label: nullableTrimmedString(record.label) ?? null,
1525
+ prompt: nullableTrimmedString(record.prompt) ?? null
1526
+ };
1527
+ }
1528
+ function normalizeAttachmentPayloads(value) {
1529
+ if (!Array.isArray(value)) return [];
1530
+ return value.map((item) => normalizeAttachmentPayload(item)).filter((item) => item !== null);
1531
+ }
1532
+ function serializeAttachmentPayload(payload) {
1533
+ return {
1534
+ type: payload.type,
1535
+ value: payload.value,
1536
+ label: payload.label ?? null,
1537
+ prompt: payload.prompt ?? null
1538
+ };
1539
+ }
1540
+ function serializeAttachmentPayloads(attachments) {
1541
+ if (!attachments || attachments.length === 0) return [];
1542
+ return attachments.map((attachment) => serializeAttachmentPayload(attachment));
1543
+ }
1544
+
1545
+ // src/core/entities/image_prompt_template.ts
1546
+ function asRecord2(value) {
1547
+ if (value && typeof value === "object" && !Array.isArray(value)) {
1548
+ return value;
1549
+ }
1550
+ return {};
1551
+ }
1552
+ function requiredString(value, fallback = "") {
1553
+ return typeof value === "string" ? value : String(value ?? fallback);
1554
+ }
1555
+ function nullableString(value) {
1556
+ if (value === null || value === void 0) return null;
1557
+ const normalized = String(value);
1558
+ return normalized.length > 0 ? normalized : null;
1559
+ }
1560
+ function normalizeStringArray(value) {
1561
+ if (!Array.isArray(value)) return [];
1562
+ return value.map((item) => String(item)).filter((item) => item.trim().length > 0);
1563
+ }
1564
+ function normalizeObject(value) {
1565
+ return asRecord2(value);
1566
+ }
1567
+ function normalizeImagePromptTemplate(value) {
1568
+ const record = asRecord2(value);
1569
+ return {
1570
+ id: requiredString(record.id),
1571
+ name: requiredString(record.name),
1572
+ description: nullableString(record.description),
1573
+ prompt: requiredString(record.prompt),
1574
+ tags: normalizeStringArray(record.tags),
1575
+ attachments: normalizeAttachmentPayloads(record.attachments),
1576
+ previewImageUrl: nullableString(record.previewImageUrl ?? record.preview_image_url),
1577
+ propsSchema: normalizeObject(record.propsSchema ?? record.props_schema),
1578
+ props: normalizeObject(record.props),
1579
+ createdAt: requiredString(record.createdAt ?? record.created_at),
1580
+ updatedAt: nullableString(record.updatedAt ?? record.updated_at)
1581
+ };
1582
+ }
1583
+ function serializeImagePromptTemplateCreate(value) {
1584
+ return {
1585
+ name: value.name,
1586
+ description: value.description ?? null,
1587
+ prompt: value.prompt,
1588
+ tags: value.tags ?? [],
1589
+ attachments: serializeAttachmentPayloads(value.attachments),
1590
+ previewImageUrl: value.previewImageUrl ?? null,
1591
+ propsSchema: value.propsSchema ?? {},
1592
+ props: value.props ?? {}
1593
+ };
1594
+ }
1595
+ function serializeImagePromptTemplateUpdate(value) {
1596
+ return {
1597
+ ...value.name !== void 0 ? { name: value.name } : {},
1598
+ ...value.description !== void 0 ? { description: value.description } : {},
1599
+ ...value.prompt !== void 0 ? { prompt: value.prompt } : {},
1600
+ ...value.tags !== void 0 ? { tags: value.tags } : {},
1601
+ ...value.attachments !== void 0 ? { attachments: serializeAttachmentPayloads(value.attachments) } : {},
1602
+ ...value.previewImageUrl !== void 0 ? { previewImageUrl: value.previewImageUrl } : {},
1603
+ ...value.propsSchema !== void 0 ? { propsSchema: value.propsSchema } : {},
1604
+ ...value.props !== void 0 ? { props: value.props } : {},
1605
+ ...value.setToNull !== void 0 ? { setToNull: value.setToNull } : {}
1606
+ };
1607
+ }
1608
+
1609
+ // src/feeef/repositories/image_prompt_templates.ts
1610
+ function toListResponse(value) {
1611
+ if (Array.isArray(value)) {
1612
+ return {
1613
+ data: value.map((item) => normalizeImagePromptTemplate(item))
1614
+ };
1615
+ }
1616
+ const record = value && typeof value === "object" ? value : {};
1617
+ const meta = record.meta && typeof record.meta === "object" ? record.meta : {};
1618
+ return {
1619
+ data: Array.isArray(record.data) ? record.data.map((item) => normalizeImagePromptTemplate(item)) : [],
1620
+ total: Number(meta.total ?? 0) || void 0,
1621
+ page: Number(meta.current_page ?? meta.currentPage ?? 0) || void 0,
1622
+ limit: Number(meta.per_page ?? meta.perPage ?? 0) || void 0
1623
+ };
1624
+ }
1625
+ var ImagePromptTemplatesRepository = class extends ModelRepository {
1626
+ constructor(client) {
1627
+ super("image_prompt_templates", client);
1628
+ }
1629
+ async find(options) {
1630
+ const response = await this.client.get(`/${this.resource}/${options.id}`, {
1631
+ params: {
1632
+ by: options.by || "id",
1633
+ ...options.params
1634
+ }
1635
+ });
1636
+ return normalizeImagePromptTemplate(response.data);
1637
+ }
1638
+ async list(options) {
1639
+ const { page, offset, limit, params, ...filters } = options || {};
1640
+ const response = await this.client.get(`/${this.resource}`, {
1641
+ params: {
1642
+ page,
1643
+ offset,
1644
+ limit,
1645
+ ...params,
1646
+ ...filters.id ? { id: filters.id } : {},
1647
+ ...filters.name ? { name: filters.name } : {},
1648
+ ...filters.nameLike ? { nameLike: filters.nameLike } : {},
1649
+ ...filters.q ? { q: filters.q } : {},
1650
+ ...filters.search ? { search: filters.search } : {},
1651
+ ...filters.tags ? { tags: filters.tags } : {},
1652
+ ...typeof filters.hasPreview === "boolean" ? { hasPreview: filters.hasPreview } : {},
1653
+ ...filters.orderBy ? { orderBy: filters.orderBy } : {}
1654
+ }
1655
+ });
1656
+ return toListResponse(response.data);
1657
+ }
1658
+ async create(dataOrOptions, params) {
1659
+ const wrapped = dataOrOptions && typeof dataOrOptions === "object" && "data" in dataOrOptions ? dataOrOptions : { data: dataOrOptions, params };
1660
+ const response = await this.client.post(
1661
+ `/${this.resource}`,
1662
+ serializeImagePromptTemplateCreate(wrapped.data),
1663
+ {
1664
+ params: wrapped.params
1665
+ }
1666
+ );
1667
+ return normalizeImagePromptTemplate(response.data);
1668
+ }
1669
+ async update(options) {
1670
+ const response = await this.client.put(
1671
+ `/${this.resource}/${options.id}`,
1672
+ serializeImagePromptTemplateUpdate(options.data),
1673
+ {
1674
+ params: options.params
1675
+ }
1676
+ );
1677
+ return normalizeImagePromptTemplate(response.data);
1678
+ }
1679
+ };
1680
+
1681
+ // src/core/entities/image_generation.ts
1682
+ function asRecord3(value) {
1683
+ if (value && typeof value === "object" && !Array.isArray(value)) {
1684
+ return value;
1685
+ }
1686
+ return {};
1687
+ }
1688
+ function nullableString2(value) {
1689
+ if (value === null || value === void 0) return null;
1690
+ const normalized = String(value);
1691
+ return normalized.length > 0 ? normalized : null;
1692
+ }
1693
+ function requiredString2(value, fallback = "") {
1694
+ return typeof value === "string" ? value : String(value ?? fallback);
1695
+ }
1696
+ function normalizeStringArray2(value) {
1697
+ if (!Array.isArray(value)) return [];
1698
+ return value.map((item) => String(item)).filter((item) => item.trim().length > 0);
1699
+ }
1700
+ function normalizeObject2(value) {
1701
+ return asRecord3(value);
1702
+ }
1703
+ function normalizeHistoryItem(value) {
1704
+ const record = asRecord3(value);
1705
+ return {
1706
+ id: requiredString2(record.id),
1707
+ createdAt: requiredString2(record.createdAt ?? record.created_at),
1708
+ generatedImageUrl: nullableString2(record.generatedImageUrl ?? record.generated_image_url),
1709
+ configs: normalizeObject2(record.configs)
1710
+ };
1711
+ }
1712
+ function normalizeUserSummary(value) {
1713
+ const record = asRecord3(value);
1714
+ if (!record.id) return null;
1715
+ return {
1716
+ id: requiredString2(record.id),
1717
+ name: nullableString2(record.name),
1718
+ photoUrl: nullableString2(record.photoUrl ?? record.photo_url)
1719
+ };
1720
+ }
1721
+ function normalizeImageGeneration(value) {
1722
+ const record = asRecord3(value);
1723
+ return {
1724
+ id: requiredString2(record.id),
1725
+ userId: nullableString2(record.userId ?? record.user_id),
1726
+ storeId: nullableString2(record.storeId ?? record.store_id),
1727
+ title: nullableString2(record.title),
1728
+ generatedImageUrl: nullableString2(record.generatedImageUrl ?? record.generated_image_url),
1729
+ configs: normalizeObject2(record.configs),
1730
+ generations: Array.isArray(record.generations) ? record.generations.map((item) => normalizeHistoryItem(item)) : [],
1731
+ status: record.status || "pending",
1732
+ tags: normalizeStringArray2(record.tags),
1733
+ createdAt: requiredString2(record.createdAt ?? record.created_at),
1734
+ updatedAt: nullableString2(record.updatedAt ?? record.updated_at),
1735
+ deletedAt: nullableString2(record.deletedAt ?? record.deleted_at),
1736
+ user: normalizeUserSummary(record.user)
1737
+ };
1738
+ }
1739
+ function normalizePaginatedResponse(value, mapper) {
1740
+ const record = asRecord3(value);
1741
+ const data = Array.isArray(record.data) ? record.data.map((item) => mapper(item)) : [];
1742
+ const meta = asRecord3(record.meta);
1743
+ const currentPage = Number(meta.current_page ?? meta.currentPage ?? 1);
1744
+ const lastPage = Number(meta.last_page ?? meta.lastPage ?? currentPage);
1745
+ const limit = Number(meta.per_page ?? meta.perPage ?? meta.limit ?? 0) || void 0;
1746
+ const total = Number(meta.total ?? 0) || void 0;
1747
+ return {
1748
+ data,
1749
+ meta,
1750
+ hasMore: currentPage < lastPage,
1751
+ total,
1752
+ page: currentPage,
1753
+ limit
1754
+ };
1755
+ }
1756
+ function toBlob(value) {
1757
+ if (value instanceof Blob) return value;
1758
+ if (value instanceof Uint8Array) return new Blob([value], { type: "image/png" });
1759
+ return new Blob([value], { type: "image/png" });
1760
+ }
1761
+ function createImageGenerationFormData(input) {
1762
+ const formData = new FormData();
1763
+ if (input.id && input.id.trim().length > 0) formData.append("id", input.id.trim());
1764
+ if (input.storeId && input.storeId.trim().length > 0)
1765
+ formData.append("storeId", input.storeId.trim());
1766
+ if (input.title && input.title.trim().length > 0) formData.append("title", input.title.trim());
1767
+ if (input.prompt && input.prompt.trim().length > 0) formData.append("prompt", input.prompt.trim());
1768
+ if (input.aspectRatio) formData.append("aspectRatio", input.aspectRatio);
1769
+ if (input.imageSize) formData.append("imageSize", input.imageSize);
1770
+ formData.append("resolution", input.resolution ?? "MEDIA_RESOLUTION_HIGH");
1771
+ if (input.systemInstructions && input.systemInstructions.trim().length > 0) {
1772
+ formData.append("systemInstructions", input.systemInstructions.trim());
1773
+ }
1774
+ if (input.attachments && input.attachments.length > 0) {
1775
+ formData.append("attachments", JSON.stringify(serializeAttachmentPayloads(input.attachments)));
1776
+ }
1777
+ if (input.model && input.model.trim().length > 0) formData.append("model", input.model.trim());
1778
+ if (typeof input.googleSearch === "boolean") {
1779
+ formData.append("googleSearch", String(input.googleSearch));
1780
+ }
1781
+ if (typeof input.imageSearch === "boolean") {
1782
+ formData.append("imageSearch", String(input.imageSearch));
1783
+ }
1784
+ if (input.imageFile) {
1785
+ const blob = toBlob(input.imageFile);
1786
+ const filename = `image_${Date.now()}.png`;
1787
+ formData.append("imageFile", blob, filename);
1788
+ }
1789
+ return formData;
1790
+ }
1791
+
1792
+ // src/feeef/repositories/image_generations.ts
1793
+ var ImageGenerationsRepository = class {
1794
+ client;
1795
+ resource = "image_generations";
1796
+ constructor(client) {
1797
+ this.client = client;
1798
+ }
1799
+ async list(options) {
1800
+ const { page = 1, limit = 10, storeId, tags, params } = options || {};
1801
+ const response = await this.client.get(`/${this.resource}`, {
1802
+ params: {
1803
+ page,
1804
+ limit,
1805
+ ...params,
1806
+ ...storeId ? { store_id: storeId } : {},
1807
+ ...tags && tags.length > 0 ? { tags } : {}
1808
+ }
1809
+ });
1810
+ return normalizePaginatedResponse(response.data, normalizeImageGeneration);
1811
+ }
1812
+ async gallery(options) {
1813
+ const { page = 1, limit = 24, params } = options || {};
1814
+ const response = await this.client.get(`/${this.resource}/gallery`, {
1815
+ params: { page, limit, ...params }
1816
+ });
1817
+ return normalizePaginatedResponse(response.data, normalizeImageGeneration);
1818
+ }
1819
+ async find(id) {
1820
+ const response = await this.client.get(`/${this.resource}/${id}`);
1821
+ return normalizeImageGeneration(response.data);
1822
+ }
1823
+ async createImageGeneration(input) {
1824
+ return this.generateImageGeneration({ ...input, id: null });
1825
+ }
1826
+ async generateImageGeneration(input) {
1827
+ const response = await this.client.post(
1828
+ `/${this.resource}/generate`,
1829
+ createImageGenerationFormData(input),
1830
+ {
1831
+ headers: {
1832
+ "Content-Type": "multipart/form-data"
1833
+ }
1834
+ }
1835
+ );
1836
+ return normalizeImageGeneration(response.data);
1837
+ }
1838
+ async rerunGeneration(id, input = {}) {
1839
+ const response = await this.client.post(
1840
+ `/${this.resource}/${id}/generate`,
1841
+ createImageGenerationFormData({ ...input, id }),
1842
+ {
1843
+ headers: {
1844
+ "Content-Type": "multipart/form-data"
1845
+ }
1846
+ }
1847
+ );
1848
+ return normalizeImageGeneration(response.data);
1849
+ }
1850
+ async setPublished(input) {
1851
+ const response = await this.client.patch(`/${this.resource}/${input.id}`, {
1852
+ status: input.isPublished ? "published" : "completed"
1853
+ });
1854
+ return normalizeImageGeneration(response.data);
1855
+ }
1856
+ async delete(id) {
1857
+ const response = await this.client.delete(`/${this.resource}/${id}`);
1858
+ return {
1859
+ success: Boolean(response.data?.success)
1860
+ };
1861
+ }
1862
+ };
1863
+
1497
1864
  // src/core/entities/order.ts
1498
1865
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
1499
1866
  OrderStatus2["draft"] = "draft";
@@ -2966,6 +3333,14 @@ var FeeeF = class {
2966
3333
  * The repository for managing product landing page templates.
2967
3334
  */
2968
3335
  productLandingPageTemplates;
3336
+ /**
3337
+ * The repository for managing image prompt templates.
3338
+ */
3339
+ imagePromptTemplates;
3340
+ /**
3341
+ * The repository for managing async image generations.
3342
+ */
3343
+ imageGenerations;
2969
3344
  /**
2970
3345
  * The repository for managing users.
2971
3346
  */
@@ -3053,6 +3428,8 @@ var FeeeF = class {
3053
3428
  this.products = new ProductRepository(this.client);
3054
3429
  this.productLandingPages = new ProductLandingPagesRepository(this.client);
3055
3430
  this.productLandingPageTemplates = new ProductLandingPageTemplatesRepository(this.client);
3431
+ this.imagePromptTemplates = new ImagePromptTemplatesRepository(this.client);
3432
+ this.imageGenerations = new ImageGenerationsRepository(this.client);
3056
3433
  this.users = new UserRepository(this.client);
3057
3434
  this.orders = new OrderRepository(this.client);
3058
3435
  this.deposits = new DepositRepository(this.client);
@@ -3475,6 +3852,7 @@ function validatePhoneNumber(phone) {
3475
3852
  return null;
3476
3853
  }
3477
3854
  export {
3855
+ ATTACHMENT_TYPES,
3478
3856
  ActionsService,
3479
3857
  CartService,
3480
3858
  CategoryRepository,
@@ -3492,6 +3870,8 @@ export {
3492
3870
  FeedbackStatus,
3493
3871
  FeeeF,
3494
3872
  GoogleSheetIntegrationApi,
3873
+ ImageGenerationsRepository,
3874
+ ImagePromptTemplatesRepository,
3495
3875
  IntegrationFactory,
3496
3876
  MetaPixelEvent,
3497
3877
  ModelRepository,
@@ -3528,6 +3908,7 @@ export {
3528
3908
  ZimouDeliveryIntegrationApi,
3529
3909
  convertDartColorToCssNumber,
3530
3910
  convertOrderEntityToOrderTrackEntity,
3911
+ createImageGenerationFormData,
3531
3912
  cssColorToHslString,
3532
3913
  dartColorToCssColor,
3533
3914
  generatePublicIntegrationsData,
@@ -3551,7 +3932,17 @@ export {
3551
3932
  generatePublicStoreIntegrations,
3552
3933
  getAvailableShippingTypes,
3553
3934
  getShippingPrice,
3935
+ isAttachmentType,
3554
3936
  isShippingAvailable,
3937
+ normalizeAttachmentPayload,
3938
+ normalizeAttachmentPayloads,
3939
+ normalizeImageGeneration,
3940
+ normalizeImagePromptTemplate,
3941
+ normalizePaginatedResponse,
3942
+ serializeAttachmentPayload,
3943
+ serializeAttachmentPayloads,
3944
+ serializeImagePromptTemplateCreate,
3945
+ serializeImagePromptTemplateUpdate,
3555
3946
  tryFixPhoneNumber,
3556
3947
  validatePhoneNumber
3557
3948
  };