digital-tools 2.1.1 → 2.3.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.
Files changed (293) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +2 -0
  3. package/dist/client.d.ts +109 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +69 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/define.d.ts +2 -2
  8. package/dist/define.d.ts.map +1 -1
  9. package/dist/define.js +22 -20
  10. package/dist/define.js.map +1 -1
  11. package/dist/function-ref.d.ts +229 -0
  12. package/dist/function-ref.d.ts.map +1 -0
  13. package/dist/function-ref.js +28 -0
  14. package/dist/function-ref.js.map +1 -0
  15. package/dist/function-sugar.d.ts +57 -0
  16. package/dist/function-sugar.d.ts.map +1 -0
  17. package/dist/function-sugar.js +79 -0
  18. package/dist/function-sugar.js.map +1 -0
  19. package/dist/index.d.ts +10 -3
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +24 -4
  22. package/dist/index.js.map +1 -1
  23. package/dist/providers/analytics/mixpanel.d.ts.map +1 -1
  24. package/dist/providers/analytics/mixpanel.js +21 -18
  25. package/dist/providers/analytics/mixpanel.js.map +1 -1
  26. package/dist/providers/calendar/cal-com.d.ts.map +1 -1
  27. package/dist/providers/calendar/cal-com.js +10 -10
  28. package/dist/providers/calendar/cal-com.js.map +1 -1
  29. package/dist/providers/calendar/google-calendar.d.ts.map +1 -1
  30. package/dist/providers/calendar/google-calendar.js +4 -4
  31. package/dist/providers/calendar/google-calendar.js.map +1 -1
  32. package/dist/providers/crm/hubspot.d.ts.map +1 -1
  33. package/dist/providers/crm/hubspot.js +107 -85
  34. package/dist/providers/crm/hubspot.js.map +1 -1
  35. package/dist/providers/development/github.d.ts.map +1 -1
  36. package/dist/providers/development/github.js +40 -43
  37. package/dist/providers/development/github.js.map +1 -1
  38. package/dist/providers/ecommerce/shopify.d.ts.map +1 -1
  39. package/dist/providers/ecommerce/shopify.js +79 -62
  40. package/dist/providers/ecommerce/shopify.js.map +1 -1
  41. package/dist/providers/email/resend.d.ts.map +1 -1
  42. package/dist/providers/email/resend.js +20 -16
  43. package/dist/providers/email/resend.js.map +1 -1
  44. package/dist/providers/email/sendgrid.d.ts.map +1 -1
  45. package/dist/providers/email/sendgrid.js +12 -9
  46. package/dist/providers/email/sendgrid.js.map +1 -1
  47. package/dist/providers/finance/stripe.d.ts.map +1 -1
  48. package/dist/providers/finance/stripe.js +44 -42
  49. package/dist/providers/finance/stripe.js.map +1 -1
  50. package/dist/providers/forms/typeform.d.ts.map +1 -1
  51. package/dist/providers/forms/typeform.js +68 -58
  52. package/dist/providers/forms/typeform.js.map +1 -1
  53. package/dist/providers/knowledge/notion.d.ts.map +1 -1
  54. package/dist/providers/knowledge/notion.js +75 -41
  55. package/dist/providers/knowledge/notion.js.map +1 -1
  56. package/dist/providers/marketing/mailchimp.d.ts.map +1 -1
  57. package/dist/providers/marketing/mailchimp.js +74 -61
  58. package/dist/providers/marketing/mailchimp.js.map +1 -1
  59. package/dist/providers/media/cloudinary.d.ts.map +1 -1
  60. package/dist/providers/media/cloudinary.js +30 -28
  61. package/dist/providers/media/cloudinary.js.map +1 -1
  62. package/dist/providers/messaging/slack.d.ts.map +1 -1
  63. package/dist/providers/messaging/slack.js +75 -58
  64. package/dist/providers/messaging/slack.js.map +1 -1
  65. package/dist/providers/messaging/twilio-sms.d.ts.map +1 -1
  66. package/dist/providers/messaging/twilio-sms.js +33 -15
  67. package/dist/providers/messaging/twilio-sms.js.map +1 -1
  68. package/dist/providers/project-management/linear.d.ts.map +1 -1
  69. package/dist/providers/project-management/linear.js +31 -27
  70. package/dist/providers/project-management/linear.js.map +1 -1
  71. package/dist/providers/spreadsheet/google-sheets.d.ts.map +1 -1
  72. package/dist/providers/spreadsheet/google-sheets.js +21 -18
  73. package/dist/providers/spreadsheet/google-sheets.js.map +1 -1
  74. package/dist/providers/spreadsheet/xlsx.d.ts.map +1 -1
  75. package/dist/providers/spreadsheet/xlsx.js +4 -4
  76. package/dist/providers/spreadsheet/xlsx.js.map +1 -1
  77. package/dist/providers/storage/index.js +1 -0
  78. package/dist/providers/storage/index.js.map +1 -1
  79. package/dist/providers/storage/s3.d.ts.map +1 -1
  80. package/dist/providers/storage/s3.js +36 -27
  81. package/dist/providers/storage/s3.js.map +1 -1
  82. package/dist/providers/support/zendesk.d.ts.map +1 -1
  83. package/dist/providers/support/zendesk.js +24 -25
  84. package/dist/providers/support/zendesk.js.map +1 -1
  85. package/dist/providers/tasks/todoist.d.ts.map +1 -1
  86. package/dist/providers/tasks/todoist.js +18 -18
  87. package/dist/providers/tasks/todoist.js.map +1 -1
  88. package/dist/providers/video-conferencing/google-meet.d.ts.map +1 -1
  89. package/dist/providers/video-conferencing/google-meet.js +11 -11
  90. package/dist/providers/video-conferencing/google-meet.js.map +1 -1
  91. package/dist/providers/video-conferencing/jitsi.js +14 -14
  92. package/dist/providers/video-conferencing/jitsi.js.map +1 -1
  93. package/dist/providers/video-conferencing/teams.d.ts.map +1 -1
  94. package/dist/providers/video-conferencing/teams.js +9 -7
  95. package/dist/providers/video-conferencing/teams.js.map +1 -1
  96. package/dist/providers/video-conferencing/zoom.d.ts.map +1 -1
  97. package/dist/providers/video-conferencing/zoom.js +26 -24
  98. package/dist/providers/video-conferencing/zoom.js.map +1 -1
  99. package/dist/tools/data.d.ts.map +1 -1
  100. package/dist/tools/data.js +5 -12
  101. package/dist/tools/data.js.map +1 -1
  102. package/dist/tools/index.d.ts +1 -0
  103. package/dist/tools/index.d.ts.map +1 -1
  104. package/dist/tools/index.js +1 -0
  105. package/dist/tools/index.js.map +1 -1
  106. package/dist/tools/system.d.ts +289 -0
  107. package/dist/tools/system.d.ts.map +1 -0
  108. package/dist/tools/system.js +752 -0
  109. package/dist/tools/system.js.map +1 -0
  110. package/dist/tools/web.d.ts.map +1 -1
  111. package/dist/tools/web.js +22 -10
  112. package/dist/tools/web.js.map +1 -1
  113. package/dist/track-record.d.ts +101 -0
  114. package/dist/track-record.d.ts.map +1 -0
  115. package/dist/track-record.js +17 -0
  116. package/dist/track-record.js.map +1 -0
  117. package/dist/types.d.ts +210 -9
  118. package/dist/types.d.ts.map +1 -1
  119. package/dist/verb-registration.d.ts +122 -0
  120. package/dist/verb-registration.d.ts.map +1 -0
  121. package/dist/verb-registration.js +176 -0
  122. package/dist/verb-registration.js.map +1 -0
  123. package/dist/worker.d.ts +93 -0
  124. package/dist/worker.d.ts.map +1 -0
  125. package/dist/worker.js +315 -0
  126. package/dist/worker.js.map +1 -0
  127. package/dist/wrap.d.ts +89 -0
  128. package/dist/wrap.d.ts.map +1 -0
  129. package/dist/wrap.js +225 -0
  130. package/dist/wrap.js.map +1 -0
  131. package/package.json +21 -4
  132. package/src/client.ts +136 -0
  133. package/src/define.ts +31 -37
  134. package/src/function-ref.ts +264 -0
  135. package/src/function-sugar.ts +134 -0
  136. package/src/index.ts +132 -10
  137. package/src/providers/analytics/mixpanel.ts +19 -18
  138. package/src/providers/calendar/cal-com.ts +29 -18
  139. package/src/providers/calendar/google-calendar.ts +20 -14
  140. package/src/providers/crm/hubspot.ts +225 -99
  141. package/src/providers/development/github.ts +206 -135
  142. package/src/providers/ecommerce/shopify.ts +250 -89
  143. package/src/providers/email/resend.ts +101 -28
  144. package/src/providers/email/sendgrid.ts +12 -9
  145. package/src/providers/finance/stripe.ts +128 -49
  146. package/src/providers/forms/typeform.ts +74 -58
  147. package/src/providers/knowledge/notion.ts +340 -88
  148. package/src/providers/marketing/mailchimp.ts +86 -70
  149. package/src/providers/media/cloudinary.ts +99 -41
  150. package/src/providers/messaging/slack.ts +283 -85
  151. package/src/providers/messaging/twilio-sms.ts +35 -15
  152. package/src/providers/project-management/linear.ts +143 -55
  153. package/src/providers/spreadsheet/google-sheets.ts +222 -56
  154. package/src/providers/spreadsheet/xlsx.ts +47 -16
  155. package/src/providers/storage/s3.ts +119 -47
  156. package/src/providers/support/zendesk.ts +196 -46
  157. package/src/providers/tasks/todoist.ts +20 -26
  158. package/src/providers/video-conferencing/google-meet.ts +17 -20
  159. package/src/providers/video-conferencing/jitsi.ts +14 -14
  160. package/src/providers/video-conferencing/teams.ts +14 -13
  161. package/src/providers/video-conferencing/zoom.ts +54 -49
  162. package/src/tools/data.ts +6 -16
  163. package/src/tools/index.ts +1 -0
  164. package/src/tools/system.ts +887 -0
  165. package/src/tools/web.ts +22 -10
  166. package/src/track-record.ts +106 -0
  167. package/src/types.ts +241 -13
  168. package/src/verb-registration.ts +197 -0
  169. package/src/worker.ts +370 -0
  170. package/src/wrap.ts +260 -0
  171. package/test/client.test.ts +146 -0
  172. package/test/communication-tools-extended.test.ts +734 -0
  173. package/test/data-tools-extended.test.ts +743 -0
  174. package/test/define-extended.test.ts +819 -0
  175. package/test/define.test.ts +150 -41
  176. package/test/entities.test.ts +623 -0
  177. package/test/extended-entities.test.ts +1228 -0
  178. package/test/provider-implementations.test.ts +725 -0
  179. package/test/provider-registry-extended.test.ts +583 -0
  180. package/test/providers/google-sheets.test.ts +851 -0
  181. package/test/providers/helpers.ts +554 -0
  182. package/test/providers/hubspot.test.ts +576 -0
  183. package/test/providers/slack.test.ts +932 -0
  184. package/test/providers/stripe.test.ts +701 -0
  185. package/test/providers.test.ts +578 -0
  186. package/test/system-tools-extended.test.ts +632 -0
  187. package/test/system.test.ts +673 -0
  188. package/test/tools.test.ts +15 -11
  189. package/test/types.test.ts +402 -0
  190. package/test/verb-registration.test.ts +395 -0
  191. package/test/web-tools.test.ts +553 -0
  192. package/test/worker-extended.test.ts +699 -0
  193. package/test/worker.test.ts +576 -0
  194. package/test/wrap.test.ts +366 -0
  195. package/tsconfig.json +3 -13
  196. package/vitest.config.ts +37 -0
  197. package/wrangler.jsonc +9 -0
  198. package/.turbo/turbo-build.log +0 -5
  199. package/dist/providers/voice/vapi.d.ts +0 -27
  200. package/dist/providers/voice/vapi.d.ts.map +0 -1
  201. package/dist/providers/voice/vapi.js +0 -440
  202. package/dist/providers/voice/vapi.js.map +0 -1
  203. package/src/define.js +0 -267
  204. package/src/entities/advertising.js +0 -999
  205. package/src/entities/ai.js +0 -756
  206. package/src/entities/analytics.js +0 -1588
  207. package/src/entities/automation.js +0 -601
  208. package/src/entities/communication.js +0 -1150
  209. package/src/entities/crm.js +0 -1386
  210. package/src/entities/design.js +0 -546
  211. package/src/entities/development.js +0 -2212
  212. package/src/entities/document.js +0 -874
  213. package/src/entities/ecommerce.js +0 -1429
  214. package/src/entities/experiment.js +0 -1039
  215. package/src/entities/finance.js +0 -3478
  216. package/src/entities/forms.js +0 -1892
  217. package/src/entities/hr.js +0 -661
  218. package/src/entities/identity.js +0 -997
  219. package/src/entities/index.js +0 -282
  220. package/src/entities/infrastructure.js +0 -1153
  221. package/src/entities/knowledge.js +0 -1438
  222. package/src/entities/marketing.js +0 -1610
  223. package/src/entities/media.js +0 -1634
  224. package/src/entities/notification.js +0 -1199
  225. package/src/entities/presentation.js +0 -1274
  226. package/src/entities/productivity.js +0 -1317
  227. package/src/entities/project-management.js +0 -1136
  228. package/src/entities/recruiting.js +0 -736
  229. package/src/entities/shipping.js +0 -509
  230. package/src/entities/signature.js +0 -1102
  231. package/src/entities/site.js +0 -222
  232. package/src/entities/spreadsheet.js +0 -1341
  233. package/src/entities/storage.js +0 -1198
  234. package/src/entities/support.js +0 -1166
  235. package/src/entities/video-conferencing.js +0 -1750
  236. package/src/entities/video.js +0 -950
  237. package/src/entities.js +0 -1663
  238. package/src/index.js +0 -74
  239. package/src/providers/analytics/index.js +0 -17
  240. package/src/providers/analytics/mixpanel.js +0 -255
  241. package/src/providers/calendar/cal-com.js +0 -303
  242. package/src/providers/calendar/google-calendar.js +0 -335
  243. package/src/providers/calendar/index.js +0 -20
  244. package/src/providers/crm/hubspot.js +0 -566
  245. package/src/providers/crm/index.js +0 -17
  246. package/src/providers/development/github.js +0 -472
  247. package/src/providers/development/index.js +0 -17
  248. package/src/providers/ecommerce/index.js +0 -17
  249. package/src/providers/ecommerce/shopify.js +0 -378
  250. package/src/providers/email/index.js +0 -20
  251. package/src/providers/email/resend.js +0 -258
  252. package/src/providers/email/sendgrid.js +0 -161
  253. package/src/providers/finance/index.js +0 -17
  254. package/src/providers/finance/stripe.js +0 -549
  255. package/src/providers/forms/index.js +0 -17
  256. package/src/providers/forms/typeform.js +0 -500
  257. package/src/providers/index.js +0 -123
  258. package/src/providers/knowledge/index.js +0 -17
  259. package/src/providers/knowledge/notion.js +0 -389
  260. package/src/providers/marketing/index.js +0 -17
  261. package/src/providers/marketing/mailchimp.js +0 -443
  262. package/src/providers/media/cloudinary.js +0 -318
  263. package/src/providers/media/index.js +0 -17
  264. package/src/providers/messaging/index.js +0 -20
  265. package/src/providers/messaging/slack.js +0 -393
  266. package/src/providers/messaging/twilio-sms.js +0 -249
  267. package/src/providers/project-management/index.js +0 -17
  268. package/src/providers/project-management/linear.js +0 -575
  269. package/src/providers/registry.js +0 -86
  270. package/src/providers/spreadsheet/google-sheets.js +0 -375
  271. package/src/providers/spreadsheet/index.js +0 -20
  272. package/src/providers/spreadsheet/xlsx.js +0 -423
  273. package/src/providers/storage/index.js +0 -24
  274. package/src/providers/storage/s3.js +0 -419
  275. package/src/providers/support/index.js +0 -17
  276. package/src/providers/support/zendesk.js +0 -373
  277. package/src/providers/tasks/index.js +0 -17
  278. package/src/providers/tasks/todoist.js +0 -286
  279. package/src/providers/types.js +0 -9
  280. package/src/providers/video-conferencing/google-meet.js +0 -286
  281. package/src/providers/video-conferencing/index.js +0 -31
  282. package/src/providers/video-conferencing/jitsi.js +0 -254
  283. package/src/providers/video-conferencing/teams.js +0 -270
  284. package/src/providers/video-conferencing/zoom.js +0 -332
  285. package/src/registry.js +0 -128
  286. package/src/tools/communication.js +0 -184
  287. package/src/tools/data.js +0 -205
  288. package/src/tools/index.js +0 -11
  289. package/src/tools/web.js +0 -137
  290. package/src/types.js +0 -10
  291. package/test/define.test.js +0 -306
  292. package/test/registry.test.js +0 -357
  293. package/test/tools.test.js +0 -363
@@ -1,378 +0,0 @@
1
- /**
2
- * Shopify E-commerce Provider
3
- *
4
- * Concrete implementation of EcommerceProvider using Shopify Admin REST API.
5
- *
6
- * @packageDocumentation
7
- */
8
- import { defineProvider } from '../registry.js';
9
- const API_VERSION = '2023-10';
10
- /**
11
- * Shopify provider info
12
- */
13
- export const shopifyInfo = {
14
- id: 'ecommerce.shopify',
15
- name: 'Shopify',
16
- description: 'Shopify e-commerce platform',
17
- category: 'ecommerce',
18
- website: 'https://www.shopify.com',
19
- docsUrl: 'https://shopify.dev/docs/api/admin-rest',
20
- requiredConfig: ['shopDomain', 'accessToken'],
21
- optionalConfig: [],
22
- };
23
- /**
24
- * Create Shopify e-commerce provider
25
- */
26
- export function createShopifyProvider(config) {
27
- let shopDomain;
28
- let accessToken;
29
- let baseUrl;
30
- function getHeaders() {
31
- return {
32
- 'Content-Type': 'application/json',
33
- 'X-Shopify-Access-Token': accessToken,
34
- };
35
- }
36
- async function makeRequest(endpoint, method = 'GET', body) {
37
- const response = await fetch(`${baseUrl}${endpoint}`, {
38
- method,
39
- headers: getHeaders(),
40
- body: body ? JSON.stringify(body) : undefined,
41
- });
42
- if (!response.ok) {
43
- const errorData = await response.json().catch(() => ({}));
44
- throw new Error(`Shopify API error: ${response.status} - ${errorData?.errors || response.statusText}`);
45
- }
46
- return response.json();
47
- }
48
- return {
49
- info: shopifyInfo,
50
- async initialize(cfg) {
51
- shopDomain = cfg.shopDomain;
52
- accessToken = cfg.accessToken;
53
- if (!shopDomain) {
54
- throw new Error('Shopify shop domain is required');
55
- }
56
- if (!accessToken) {
57
- throw new Error('Shopify access token is required');
58
- }
59
- // Ensure domain has proper format
60
- const domain = shopDomain.includes('.myshopify.com')
61
- ? shopDomain
62
- : `${shopDomain}.myshopify.com`;
63
- baseUrl = `https://${domain}/admin/api/${API_VERSION}`;
64
- },
65
- async healthCheck() {
66
- const start = Date.now();
67
- try {
68
- await makeRequest('/shop.json', 'GET');
69
- return {
70
- healthy: true,
71
- latencyMs: Date.now() - start,
72
- message: 'Connected',
73
- checkedAt: new Date(),
74
- };
75
- }
76
- catch (error) {
77
- return {
78
- healthy: false,
79
- latencyMs: Date.now() - start,
80
- message: error instanceof Error ? error.message : 'Unknown error',
81
- checkedAt: new Date(),
82
- };
83
- }
84
- },
85
- async dispose() {
86
- // No cleanup needed
87
- },
88
- async createProduct(product) {
89
- const shopifyProduct = {
90
- title: product.title,
91
- body_html: product.description,
92
- vendor: 'Default',
93
- product_type: '',
94
- tags: product.tags?.join(', ') || '',
95
- status: product.status || 'active',
96
- };
97
- // Add variants
98
- if (product.variants && product.variants.length > 0) {
99
- shopifyProduct.variants = product.variants.map((v) => ({
100
- title: v.title,
101
- price: v.price.toString(),
102
- sku: v.sku,
103
- inventory_quantity: v.inventory || 0,
104
- }));
105
- }
106
- else {
107
- // Single variant
108
- shopifyProduct.variants = [
109
- {
110
- title: 'Default Title',
111
- price: product.price.toString(),
112
- sku: product.sku,
113
- inventory_quantity: product.inventory || 0,
114
- },
115
- ];
116
- }
117
- // Add images
118
- if (product.images && product.images.length > 0) {
119
- shopifyProduct.images = product.images.map((url) => ({ src: url }));
120
- }
121
- const response = await makeRequest('/products.json', 'POST', {
122
- product: shopifyProduct,
123
- });
124
- return mapShopifyProduct(response.product);
125
- },
126
- async getProduct(productId) {
127
- try {
128
- const response = await makeRequest(`/products/${productId}.json`, 'GET');
129
- return mapShopifyProduct(response.product);
130
- }
131
- catch (error) {
132
- return null;
133
- }
134
- },
135
- async updateProduct(productId, updates) {
136
- const shopifyUpdates = {};
137
- if (updates.title)
138
- shopifyUpdates.title = updates.title;
139
- if (updates.description)
140
- shopifyUpdates.body_html = updates.description;
141
- if (updates.tags)
142
- shopifyUpdates.tags = updates.tags.join(', ');
143
- if (updates.status)
144
- shopifyUpdates.status = updates.status;
145
- // Handle images update
146
- if (updates.images) {
147
- shopifyUpdates.images = updates.images.map((url) => ({ src: url }));
148
- }
149
- const response = await makeRequest(`/products/${productId}.json`, 'PUT', {
150
- product: shopifyUpdates,
151
- });
152
- return mapShopifyProduct(response.product);
153
- },
154
- async deleteProduct(productId) {
155
- try {
156
- await makeRequest(`/products/${productId}.json`, 'DELETE');
157
- return true;
158
- }
159
- catch (error) {
160
- return false;
161
- }
162
- },
163
- async listProducts(options) {
164
- const params = new URLSearchParams();
165
- if (options?.limit)
166
- params.append('limit', options.limit.toString());
167
- if (options?.status)
168
- params.append('status', options.status);
169
- if (options?.vendor)
170
- params.append('vendor', options.vendor);
171
- if (options?.cursor)
172
- params.append('page_info', options.cursor);
173
- const queryString = params.toString();
174
- const endpoint = `/products.json${queryString ? `?${queryString}` : ''}`;
175
- const response = await makeRequest(endpoint, 'GET');
176
- return {
177
- items: response.products.map(mapShopifyProduct),
178
- hasMore: response.products.length === (options?.limit || 50),
179
- total: undefined, // Shopify doesn't provide total count in products endpoint
180
- };
181
- },
182
- async getOrder(orderId) {
183
- try {
184
- const response = await makeRequest(`/orders/${orderId}.json`, 'GET');
185
- return mapShopifyOrder(response.order);
186
- }
187
- catch (error) {
188
- return null;
189
- }
190
- },
191
- async listOrders(options) {
192
- const params = new URLSearchParams();
193
- if (options?.limit)
194
- params.append('limit', options.limit.toString());
195
- if (options?.status)
196
- params.append('status', options.status);
197
- if (options?.financialStatus)
198
- params.append('financial_status', options.financialStatus);
199
- if (options?.fulfillmentStatus)
200
- params.append('fulfillment_status', options.fulfillmentStatus);
201
- if (options?.customerId)
202
- params.append('customer_id', options.customerId);
203
- if (options?.since)
204
- params.append('created_at_min', options.since.toISOString());
205
- if (options?.until)
206
- params.append('created_at_max', options.until.toISOString());
207
- if (options?.cursor)
208
- params.append('page_info', options.cursor);
209
- const queryString = params.toString();
210
- const endpoint = `/orders.json${queryString ? `?${queryString}` : ''}`;
211
- const response = await makeRequest(endpoint, 'GET');
212
- return {
213
- items: response.orders.map(mapShopifyOrder),
214
- hasMore: response.orders.length === (options?.limit || 50),
215
- total: undefined,
216
- };
217
- },
218
- async updateOrderStatus(orderId, status) {
219
- const response = await makeRequest(`/orders/${orderId}.json`, 'PUT', {
220
- order: {
221
- id: orderId,
222
- tags: status,
223
- },
224
- });
225
- return mapShopifyOrder(response.order);
226
- },
227
- async getEcommerceCustomer(customerId) {
228
- try {
229
- const response = await makeRequest(`/customers/${customerId}.json`, 'GET');
230
- return mapShopifyCustomer(response.customer);
231
- }
232
- catch (error) {
233
- return null;
234
- }
235
- },
236
- async listEcommerceCustomers(options) {
237
- const params = new URLSearchParams();
238
- if (options?.limit)
239
- params.append('limit', options.limit.toString());
240
- if (options?.cursor)
241
- params.append('page_info', options.cursor);
242
- const queryString = params.toString();
243
- const endpoint = `/customers.json${queryString ? `?${queryString}` : ''}`;
244
- const response = await makeRequest(endpoint, 'GET');
245
- return {
246
- items: response.customers.map(mapShopifyCustomer),
247
- hasMore: response.customers.length === (options?.limit || 50),
248
- total: undefined,
249
- };
250
- },
251
- async updateInventory(productId, variantId, quantity) {
252
- try {
253
- // First get the inventory item ID from the variant
254
- const variantResponse = await makeRequest(`/variants/${variantId}.json`, 'GET');
255
- const inventoryItemId = variantResponse.variant.inventory_item_id;
256
- // Get inventory levels
257
- const levelsResponse = await makeRequest(`/inventory_levels.json?inventory_item_ids=${inventoryItemId}`, 'GET');
258
- if (levelsResponse.inventory_levels.length === 0) {
259
- throw new Error('No inventory levels found for this variant');
260
- }
261
- const locationId = levelsResponse.inventory_levels[0].location_id;
262
- // Set the inventory level
263
- await makeRequest('/inventory_levels/set.json', 'POST', {
264
- location_id: locationId,
265
- inventory_item_id: inventoryItemId,
266
- available: quantity,
267
- });
268
- return true;
269
- }
270
- catch (error) {
271
- return false;
272
- }
273
- },
274
- };
275
- }
276
- /**
277
- * Map Shopify product to our format
278
- */
279
- function mapShopifyProduct(product) {
280
- const firstVariant = product.variants?.[0];
281
- return {
282
- id: product.id.toString(),
283
- title: product.title,
284
- description: product.body_html,
285
- price: parseFloat(firstVariant?.price || '0'),
286
- compareAtPrice: firstVariant?.compare_at_price
287
- ? parseFloat(firstVariant.compare_at_price)
288
- : undefined,
289
- sku: firstVariant?.sku,
290
- inventory: firstVariant?.inventory_quantity,
291
- images: product.images?.map((img) => img.src) || [],
292
- variants: product.variants?.map((v) => ({
293
- id: v.id.toString(),
294
- title: v.title,
295
- price: parseFloat(v.price),
296
- sku: v.sku,
297
- inventory: v.inventory_quantity,
298
- })) || [],
299
- tags: product.tags ? product.tags.split(', ') : [],
300
- status: product.status,
301
- url: product.admin_graphql_api_id,
302
- createdAt: new Date(product.created_at),
303
- updatedAt: new Date(product.updated_at),
304
- };
305
- }
306
- /**
307
- * Map Shopify order to our format
308
- */
309
- function mapShopifyOrder(order) {
310
- return {
311
- id: order.id.toString(),
312
- orderNumber: order.name || order.order_number?.toString(),
313
- status: order.cancelled_at ? 'cancelled' : order.closed_at ? 'closed' : 'open',
314
- financialStatus: order.financial_status,
315
- fulfillmentStatus: order.fulfillment_status || 'unfulfilled',
316
- customerId: order.customer?.id?.toString(),
317
- email: order.email || order.customer?.email || '',
318
- lineItems: order.line_items?.map((item) => ({
319
- productId: item.product_id?.toString() || '',
320
- variantId: item.variant_id?.toString(),
321
- title: item.title,
322
- quantity: item.quantity,
323
- price: parseFloat(item.price),
324
- })) || [],
325
- subtotal: parseFloat(order.subtotal_price || '0'),
326
- tax: parseFloat(order.total_tax || '0'),
327
- shipping: parseFloat(order.total_shipping_price_set?.shop_money?.amount || '0'),
328
- total: parseFloat(order.total_price || '0'),
329
- currency: order.currency,
330
- shippingAddress: order.shipping_address
331
- ? {
332
- firstName: order.shipping_address.first_name,
333
- lastName: order.shipping_address.last_name,
334
- address1: order.shipping_address.address1,
335
- address2: order.shipping_address.address2,
336
- city: order.shipping_address.city,
337
- province: order.shipping_address.province,
338
- postalCode: order.shipping_address.zip,
339
- country: order.shipping_address.country,
340
- phone: order.shipping_address.phone,
341
- }
342
- : undefined,
343
- billingAddress: order.billing_address
344
- ? {
345
- firstName: order.billing_address.first_name,
346
- lastName: order.billing_address.last_name,
347
- address1: order.billing_address.address1,
348
- address2: order.billing_address.address2,
349
- city: order.billing_address.city,
350
- province: order.billing_address.province,
351
- postalCode: order.billing_address.zip,
352
- country: order.billing_address.country,
353
- phone: order.billing_address.phone,
354
- }
355
- : undefined,
356
- createdAt: new Date(order.created_at),
357
- updatedAt: new Date(order.updated_at),
358
- };
359
- }
360
- /**
361
- * Map Shopify customer to our format
362
- */
363
- function mapShopifyCustomer(customer) {
364
- return {
365
- id: customer.id.toString(),
366
- email: customer.email,
367
- firstName: customer.first_name,
368
- lastName: customer.last_name,
369
- phone: customer.phone,
370
- ordersCount: customer.orders_count || 0,
371
- totalSpent: parseFloat(customer.total_spent || '0'),
372
- createdAt: new Date(customer.created_at),
373
- };
374
- }
375
- /**
376
- * Shopify provider definition
377
- */
378
- export const shopifyProvider = defineProvider(shopifyInfo, async (config) => createShopifyProvider(config));
@@ -1,20 +0,0 @@
1
- /**
2
- * Email Providers
3
- *
4
- * @packageDocumentation
5
- */
6
- export { sendgridInfo, sendgridProvider, createSendGridProvider } from './sendgrid.js';
7
- export { resendInfo, resendProvider, createResendProvider } from './resend.js';
8
- import { sendgridProvider } from './sendgrid.js';
9
- import { resendProvider } from './resend.js';
10
- /**
11
- * Register all email providers
12
- */
13
- export function registerEmailProviders() {
14
- sendgridProvider.register();
15
- resendProvider.register();
16
- }
17
- /**
18
- * All email providers
19
- */
20
- export const emailProviders = [sendgridProvider, resendProvider];
@@ -1,258 +0,0 @@
1
- /**
2
- * Resend Email Provider
3
- *
4
- * Concrete implementation of EmailProvider using Resend API.
5
- *
6
- * @packageDocumentation
7
- */
8
- import { defineProvider } from '../registry.js';
9
- const RESEND_API_URL = 'https://api.resend.com';
10
- /**
11
- * Resend provider info
12
- */
13
- export const resendInfo = {
14
- id: 'email.resend',
15
- name: 'Resend',
16
- description: 'Modern email API for developers',
17
- category: 'email',
18
- website: 'https://resend.com',
19
- docsUrl: 'https://resend.com/docs',
20
- requiredConfig: ['apiKey'],
21
- optionalConfig: ['defaultFrom'],
22
- };
23
- /**
24
- * Create Resend email provider
25
- */
26
- export function createResendProvider(config) {
27
- let apiKey;
28
- let defaultFrom;
29
- return {
30
- info: resendInfo,
31
- async initialize(cfg) {
32
- apiKey = cfg.apiKey;
33
- defaultFrom = cfg.defaultFrom;
34
- if (!apiKey) {
35
- throw new Error('Resend API key is required');
36
- }
37
- },
38
- async healthCheck() {
39
- const start = Date.now();
40
- try {
41
- const response = await fetch(`${RESEND_API_URL}/domains`, {
42
- headers: {
43
- Authorization: `Bearer ${apiKey}`,
44
- },
45
- });
46
- return {
47
- healthy: response.ok,
48
- latencyMs: Date.now() - start,
49
- message: response.ok ? 'Connected' : `HTTP ${response.status}`,
50
- checkedAt: new Date(),
51
- };
52
- }
53
- catch (error) {
54
- return {
55
- healthy: false,
56
- latencyMs: Date.now() - start,
57
- message: error instanceof Error ? error.message : 'Unknown error',
58
- checkedAt: new Date(),
59
- };
60
- }
61
- },
62
- async dispose() {
63
- // No cleanup needed
64
- },
65
- async send(options) {
66
- const from = options.from || defaultFrom;
67
- if (!from) {
68
- return {
69
- success: false,
70
- error: { code: 'MISSING_FROM', message: 'From address is required' },
71
- };
72
- }
73
- const body = {
74
- from,
75
- to: options.to,
76
- subject: options.subject,
77
- ...(options.cc && { cc: options.cc }),
78
- ...(options.bcc && { bcc: options.bcc }),
79
- ...(options.replyTo && { reply_to: options.replyTo }),
80
- ...(options.text && { text: options.text }),
81
- ...(options.html && { html: options.html }),
82
- ...(options.headers && { headers: options.headers }),
83
- ...(options.tags && { tags: options.tags.map((name) => ({ name })) }),
84
- };
85
- if (options.attachments?.length) {
86
- body.attachments = options.attachments.map((att) => ({
87
- filename: att.filename,
88
- content: typeof att.content === 'string' ? att.content : att.content.toString('base64'),
89
- content_type: att.contentType,
90
- }));
91
- }
92
- if (options.sendAt) {
93
- body.scheduled_at = options.sendAt.toISOString();
94
- }
95
- try {
96
- const response = await fetch(`${RESEND_API_URL}/emails`, {
97
- method: 'POST',
98
- headers: {
99
- 'Content-Type': 'application/json',
100
- Authorization: `Bearer ${apiKey}`,
101
- },
102
- body: JSON.stringify(body),
103
- });
104
- const data = await response.json();
105
- if (response.ok) {
106
- return {
107
- success: true,
108
- messageId: data.id,
109
- };
110
- }
111
- return {
112
- success: false,
113
- error: {
114
- code: data.name || `HTTP_${response.status}`,
115
- message: data.message || response.statusText,
116
- },
117
- };
118
- }
119
- catch (error) {
120
- return {
121
- success: false,
122
- error: {
123
- code: 'NETWORK_ERROR',
124
- message: error instanceof Error ? error.message : 'Unknown error',
125
- },
126
- };
127
- }
128
- },
129
- async sendBatch(emails) {
130
- // Resend has a batch endpoint
131
- const from = defaultFrom;
132
- const batch = emails.map((options) => ({
133
- from: options.from || from,
134
- to: options.to,
135
- subject: options.subject,
136
- ...(options.cc && { cc: options.cc }),
137
- ...(options.bcc && { bcc: options.bcc }),
138
- ...(options.replyTo && { reply_to: options.replyTo }),
139
- ...(options.text && { text: options.text }),
140
- ...(options.html && { html: options.html }),
141
- }));
142
- try {
143
- const response = await fetch(`${RESEND_API_URL}/emails/batch`, {
144
- method: 'POST',
145
- headers: {
146
- 'Content-Type': 'application/json',
147
- Authorization: `Bearer ${apiKey}`,
148
- },
149
- body: JSON.stringify(batch),
150
- });
151
- const data = await response.json();
152
- if (response.ok) {
153
- return data.data.map((item) => ({
154
- success: true,
155
- messageId: item.id,
156
- }));
157
- }
158
- // If batch fails, return error for all
159
- return emails.map(() => ({
160
- success: false,
161
- error: {
162
- code: data.name || `HTTP_${response.status}`,
163
- message: data.message || response.statusText,
164
- },
165
- }));
166
- }
167
- catch (error) {
168
- return emails.map(() => ({
169
- success: false,
170
- error: {
171
- code: 'NETWORK_ERROR',
172
- message: error instanceof Error ? error.message : 'Unknown error',
173
- },
174
- }));
175
- }
176
- },
177
- async get(messageId) {
178
- try {
179
- const response = await fetch(`${RESEND_API_URL}/emails/${messageId}`, {
180
- headers: {
181
- Authorization: `Bearer ${apiKey}`,
182
- },
183
- });
184
- if (!response.ok) {
185
- if (response.status === 404)
186
- return null;
187
- throw new Error(`HTTP ${response.status}`);
188
- }
189
- const data = (await response.json());
190
- return {
191
- id: data.id,
192
- from: data.from,
193
- to: Array.isArray(data.to) ? data.to : [data.to],
194
- cc: data.cc,
195
- bcc: data.bcc,
196
- subject: data.subject,
197
- text: data.text,
198
- html: data.html,
199
- status: mapResendStatus(data.last_event),
200
- sentAt: data.created_at ? new Date(data.created_at) : undefined,
201
- };
202
- }
203
- catch {
204
- return null;
205
- }
206
- },
207
- async verifyDomain(domain) {
208
- const response = await fetch(`${RESEND_API_URL}/domains`, {
209
- method: 'POST',
210
- headers: {
211
- 'Content-Type': 'application/json',
212
- Authorization: `Bearer ${apiKey}`,
213
- },
214
- body: JSON.stringify({ name: domain }),
215
- });
216
- const data = (await response.json());
217
- return {
218
- domain: data.name,
219
- verified: data.status === 'verified',
220
- dnsRecords: data.records?.map((r) => ({
221
- type: r.type,
222
- name: r.name,
223
- value: r.value,
224
- verified: r.status === 'verified',
225
- })) || [],
226
- };
227
- },
228
- async listDomains() {
229
- const response = await fetch(`${RESEND_API_URL}/domains`, {
230
- headers: {
231
- Authorization: `Bearer ${apiKey}`,
232
- },
233
- });
234
- const data = (await response.json());
235
- return data.data?.map((d) => ({
236
- domain: d.name,
237
- verified: d.status === 'verified',
238
- createdAt: new Date(d.created_at),
239
- })) || [];
240
- },
241
- };
242
- }
243
- function mapResendStatus(event) {
244
- switch (event) {
245
- case 'delivered':
246
- return 'delivered';
247
- case 'bounced':
248
- return 'bounced';
249
- case 'complained':
250
- return 'failed';
251
- default:
252
- return 'sent';
253
- }
254
- }
255
- /**
256
- * Resend provider definition
257
- */
258
- export const resendProvider = defineProvider(resendInfo, async (config) => createResendProvider(config));