feeef 0.7.5 → 0.8.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/build/index.js CHANGED
@@ -1494,6 +1494,372 @@ 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
+ formData.append("resolution", input.resolution ?? "MEDIA_RESOLUTION_LOW");
1770
+ if (input.systemInstructions && input.systemInstructions.trim().length > 0) {
1771
+ formData.append("systemInstructions", input.systemInstructions.trim());
1772
+ }
1773
+ if (input.attachments && input.attachments.length > 0) {
1774
+ formData.append("attachments", JSON.stringify(serializeAttachmentPayloads(input.attachments)));
1775
+ }
1776
+ if (input.model && input.model.trim().length > 0) formData.append("model", input.model.trim());
1777
+ if (typeof input.googleSearch === "boolean") {
1778
+ formData.append("googleSearch", String(input.googleSearch));
1779
+ }
1780
+ if (typeof input.imageSearch === "boolean") {
1781
+ formData.append("imageSearch", String(input.imageSearch));
1782
+ }
1783
+ if (input.imageFile) {
1784
+ const blob = toBlob(input.imageFile);
1785
+ const filename = `image_${Date.now()}.png`;
1786
+ formData.append("imageFile", blob, filename);
1787
+ }
1788
+ return formData;
1789
+ }
1790
+
1791
+ // src/feeef/repositories/image_generations.ts
1792
+ var ImageGenerationsRepository = class {
1793
+ client;
1794
+ resource = "image_generations";
1795
+ constructor(client) {
1796
+ this.client = client;
1797
+ }
1798
+ async list(options) {
1799
+ const { page = 1, limit = 10, storeId, tags, params } = options || {};
1800
+ const response = await this.client.get(`/${this.resource}`, {
1801
+ params: {
1802
+ page,
1803
+ limit,
1804
+ ...params,
1805
+ ...storeId ? { store_id: storeId } : {},
1806
+ ...tags && tags.length > 0 ? { tags } : {}
1807
+ }
1808
+ });
1809
+ return normalizePaginatedResponse(response.data, normalizeImageGeneration);
1810
+ }
1811
+ async gallery(options) {
1812
+ const { page = 1, limit = 24, params } = options || {};
1813
+ const response = await this.client.get(`/${this.resource}/gallery`, {
1814
+ params: { page, limit, ...params }
1815
+ });
1816
+ return normalizePaginatedResponse(response.data, normalizeImageGeneration);
1817
+ }
1818
+ async find(id) {
1819
+ const response = await this.client.get(`/${this.resource}/${id}`);
1820
+ return normalizeImageGeneration(response.data);
1821
+ }
1822
+ async createImageGeneration(input) {
1823
+ return this.generateImageGeneration({ ...input, id: null });
1824
+ }
1825
+ async generateImageGeneration(input) {
1826
+ const response = await this.client.post(
1827
+ `/${this.resource}/generate`,
1828
+ createImageGenerationFormData(input),
1829
+ {
1830
+ headers: {
1831
+ "Content-Type": "multipart/form-data"
1832
+ }
1833
+ }
1834
+ );
1835
+ return normalizeImageGeneration(response.data);
1836
+ }
1837
+ async rerunGeneration(id, input = {}) {
1838
+ const response = await this.client.post(
1839
+ `/${this.resource}/${id}/generate`,
1840
+ createImageGenerationFormData({ ...input, id }),
1841
+ {
1842
+ headers: {
1843
+ "Content-Type": "multipart/form-data"
1844
+ }
1845
+ }
1846
+ );
1847
+ return normalizeImageGeneration(response.data);
1848
+ }
1849
+ async setPublished(input) {
1850
+ const response = await this.client.patch(`/${this.resource}/${input.id}`, {
1851
+ status: input.isPublished ? "published" : "completed"
1852
+ });
1853
+ return normalizeImageGeneration(response.data);
1854
+ }
1855
+ async delete(id) {
1856
+ const response = await this.client.delete(`/${this.resource}/${id}`);
1857
+ return {
1858
+ success: Boolean(response.data?.success)
1859
+ };
1860
+ }
1861
+ };
1862
+
1497
1863
  // src/core/entities/order.ts
1498
1864
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
1499
1865
  OrderStatus2["draft"] = "draft";
@@ -2966,6 +3332,14 @@ var FeeeF = class {
2966
3332
  * The repository for managing product landing page templates.
2967
3333
  */
2968
3334
  productLandingPageTemplates;
3335
+ /**
3336
+ * The repository for managing image prompt templates.
3337
+ */
3338
+ imagePromptTemplates;
3339
+ /**
3340
+ * The repository for managing async image generations.
3341
+ */
3342
+ imageGenerations;
2969
3343
  /**
2970
3344
  * The repository for managing users.
2971
3345
  */
@@ -3053,6 +3427,8 @@ var FeeeF = class {
3053
3427
  this.products = new ProductRepository(this.client);
3054
3428
  this.productLandingPages = new ProductLandingPagesRepository(this.client);
3055
3429
  this.productLandingPageTemplates = new ProductLandingPageTemplatesRepository(this.client);
3430
+ this.imagePromptTemplates = new ImagePromptTemplatesRepository(this.client);
3431
+ this.imageGenerations = new ImageGenerationsRepository(this.client);
3056
3432
  this.users = new UserRepository(this.client);
3057
3433
  this.orders = new OrderRepository(this.client);
3058
3434
  this.deposits = new DepositRepository(this.client);
@@ -3475,6 +3851,7 @@ function validatePhoneNumber(phone) {
3475
3851
  return null;
3476
3852
  }
3477
3853
  export {
3854
+ ATTACHMENT_TYPES,
3478
3855
  ActionsService,
3479
3856
  CartService,
3480
3857
  CategoryRepository,
@@ -3492,6 +3869,8 @@ export {
3492
3869
  FeedbackStatus,
3493
3870
  FeeeF,
3494
3871
  GoogleSheetIntegrationApi,
3872
+ ImageGenerationsRepository,
3873
+ ImagePromptTemplatesRepository,
3495
3874
  IntegrationFactory,
3496
3875
  MetaPixelEvent,
3497
3876
  ModelRepository,
@@ -3528,6 +3907,7 @@ export {
3528
3907
  ZimouDeliveryIntegrationApi,
3529
3908
  convertDartColorToCssNumber,
3530
3909
  convertOrderEntityToOrderTrackEntity,
3910
+ createImageGenerationFormData,
3531
3911
  cssColorToHslString,
3532
3912
  dartColorToCssColor,
3533
3913
  generatePublicIntegrationsData,
@@ -3551,7 +3931,17 @@ export {
3551
3931
  generatePublicStoreIntegrations,
3552
3932
  getAvailableShippingTypes,
3553
3933
  getShippingPrice,
3934
+ isAttachmentType,
3554
3935
  isShippingAvailable,
3936
+ normalizeAttachmentPayload,
3937
+ normalizeAttachmentPayloads,
3938
+ normalizeImageGeneration,
3939
+ normalizeImagePromptTemplate,
3940
+ normalizePaginatedResponse,
3941
+ serializeAttachmentPayload,
3942
+ serializeAttachmentPayloads,
3943
+ serializeImagePromptTemplateCreate,
3944
+ serializeImagePromptTemplateUpdate,
3555
3945
  tryFixPhoneNumber,
3556
3946
  validatePhoneNumber
3557
3947
  };