@useairfoil/producer-shopify 0.2.0 → 0.2.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.
Files changed (60) hide show
  1. package/README.md +85 -248
  2. package/dist/index.d.mts +6993 -0
  3. package/dist/index.mjs +3 -0
  4. package/dist/main.d.mts +1 -0
  5. package/dist/main.mjs +698 -0
  6. package/dist/main.mjs.map +1 -0
  7. package/dist/manifest.d.mts +32 -0
  8. package/dist/manifest.mjs +51 -0
  9. package/dist/manifest.mjs.map +1 -0
  10. package/dist/{chunk-Bp6m_JJh.js → rolldown-runtime-D7D4PA-g.mjs} +4 -4
  11. package/dist/src-Bgvuhcfk.mjs +2473 -0
  12. package/dist/src-Bgvuhcfk.mjs.map +1 -0
  13. package/package.json +19 -19
  14. package/src/{auth.ts → api/auth.ts} +15 -35
  15. package/src/api/client.ts +429 -0
  16. package/src/api/graphql.ts +221 -0
  17. package/src/api/http.ts +25 -0
  18. package/src/connector.ts +266 -163
  19. package/src/create-table.ts +5 -0
  20. package/src/demo/customers.ts +412 -0
  21. package/src/demo/index.ts +31 -0
  22. package/src/demo/setup.ts +63 -0
  23. package/src/demo/shared.ts +114 -0
  24. package/src/index.ts +35 -21
  25. package/src/main.ts +8 -8
  26. package/src/manifest.ts +4 -55
  27. package/src/resources/carts/row.ts +58 -0
  28. package/src/resources/carts/webhook.ts +98 -0
  29. package/src/resources/customers/graphql.ts +175 -0
  30. package/src/resources/customers/row.ts +112 -0
  31. package/src/resources/customers/webhook.ts +30 -0
  32. package/src/resources/orders/graphql.ts +419 -0
  33. package/src/resources/orders/row.ts +180 -0
  34. package/src/resources/orders/webhook.ts +248 -0
  35. package/src/resources/products/graphql.ts +142 -0
  36. package/src/resources/products/row.ts +92 -0
  37. package/src/resources/products/webhook.ts +130 -0
  38. package/src/resources/refunds/graphql.ts +196 -0
  39. package/src/resources/refunds/row.ts +97 -0
  40. package/src/resources/refunds/webhook.ts +123 -0
  41. package/src/resources/shared.ts +293 -0
  42. package/src/sandbox.ts +3 -3
  43. package/src/start.ts +3 -5
  44. package/src/tables.ts +15 -0
  45. package/dist/index.d.ts +0 -965
  46. package/dist/index.js +0 -4
  47. package/dist/main.d.ts +0 -1
  48. package/dist/main.js +0 -49
  49. package/dist/main.js.map +0 -1
  50. package/dist/manifest-BFfx2LkS.js +0 -91
  51. package/dist/manifest-BFfx2LkS.js.map +0 -1
  52. package/dist/manifest-CPOEExQU.d.ts +0 -34
  53. package/dist/manifest.d.ts +0 -2
  54. package/dist/manifest.js +0 -3
  55. package/dist/src-DqmiLrYS.js +0 -984
  56. package/dist/src-DqmiLrYS.js.map +0 -1
  57. package/src/api.ts +0 -636
  58. package/src/schemas.ts +0 -319
  59. package/src/throttle.ts +0 -89
  60. package/src/transient-retry.ts +0 -74
@@ -0,0 +1,419 @@
1
+ import * as Schema from "effect/Schema";
2
+
3
+ import {
4
+ AddressFields,
5
+ DiscountAllocationFields,
6
+ GraphQLAddressSchema,
7
+ GraphQLAttributeSchema,
8
+ GraphQLDiscountAllocationSchema,
9
+ GraphQLMoneyBagSchema,
10
+ GraphQLTaxLineSchema,
11
+ MoneyBagFields,
12
+ type Nodes,
13
+ PageInfoFields,
14
+ TaxLineFields,
15
+ connection,
16
+ emptyText,
17
+ fromGraphQL,
18
+ idRef,
19
+ normalizeAmount,
20
+ pageQuery,
21
+ } from "../shared";
22
+ import {
23
+ DiscountAllocationMethodSchema,
24
+ type DiscountApplication,
25
+ type DiscountApplicationType,
26
+ DiscountTargetSelectionSchema,
27
+ DiscountTargetTypeSchema,
28
+ type Order,
29
+ OrderCancelReasonSchema,
30
+ OrderFinancialStatusSchema,
31
+ } from "./row";
32
+
33
+ const LineItemFields = `
34
+ id
35
+ name
36
+ title
37
+ variantTitle
38
+ sku
39
+ vendor
40
+ product { id }
41
+ variant { id }
42
+ quantity
43
+ currentQuantity
44
+ taxable
45
+ requiresShipping
46
+ isGiftCard
47
+ originalUnitPriceSet { ${MoneyBagFields} }
48
+ totalDiscountSet { ${MoneyBagFields} }
49
+ taxLines { ${TaxLineFields} }
50
+ discountAllocations { ${DiscountAllocationFields} }
51
+ customAttributes { key value }
52
+ `;
53
+
54
+ const ShippingLineFields = `
55
+ id
56
+ title
57
+ code
58
+ source
59
+ carrierIdentifier
60
+ phone
61
+ isRemoved
62
+ originalPriceSet { ${MoneyBagFields} }
63
+ discountedPriceSet { ${MoneyBagFields} }
64
+ currentDiscountedPriceSet { ${MoneyBagFields} }
65
+ taxLines { ${TaxLineFields} }
66
+ discountAllocations { ${DiscountAllocationFields} }
67
+ `;
68
+
69
+ const DiscountApplicationFields = `
70
+ __typename
71
+ index
72
+ allocationMethod
73
+ targetSelection
74
+ targetType
75
+ value {
76
+ __typename
77
+ ... on MoneyV2 { amount }
78
+ ... on PricingPercentageValue { percentage }
79
+ }
80
+ ... on DiscountCodeApplication { code }
81
+ ... on ManualDiscountApplication { title description }
82
+ ... on AutomaticDiscountApplication { title }
83
+ ... on ScriptDiscountApplication { title }
84
+ `;
85
+
86
+ export const OrderFields = `
87
+ id
88
+ legacyResourceId
89
+ name
90
+ email
91
+ phone
92
+ customer { id }
93
+ customerLocale
94
+ customerAcceptsMarketing
95
+ billingAddress { ${AddressFields} }
96
+ shippingAddress { ${AddressFields} }
97
+ note
98
+ customAttributes { key value }
99
+ tags
100
+ confirmationNumber
101
+ poNumber
102
+ sourceName
103
+ sourceIdentifier
104
+ app { id }
105
+ paymentGatewayNames
106
+ test
107
+ taxesIncluded
108
+ taxExempt
109
+ dutiesIncluded
110
+ estimatedTaxes
111
+ totalWeight
112
+ displayFinancialStatus
113
+ cancelReason
114
+ cancelledAt
115
+ closedAt
116
+ processedAt
117
+ createdAt
118
+ updatedAt
119
+ currencyCode
120
+ presentmentCurrencyCode
121
+ discountCodes
122
+ discountApplications(first: 25) { nodes { ${DiscountApplicationFields} } ${PageInfoFields} }
123
+ subtotalPriceSet { ${MoneyBagFields} }
124
+ currentSubtotalPriceSet { ${MoneyBagFields} }
125
+ totalDiscountsSet { ${MoneyBagFields} }
126
+ currentTotalDiscountsSet { ${MoneyBagFields} }
127
+ totalShippingPriceSet { ${MoneyBagFields} }
128
+ currentShippingPriceSet { ${MoneyBagFields} }
129
+ totalTaxSet { ${MoneyBagFields} }
130
+ currentTotalTaxSet { ${MoneyBagFields} }
131
+ originalTotalDutiesSet { ${MoneyBagFields} }
132
+ currentTotalDutiesSet { ${MoneyBagFields} }
133
+ totalPriceSet { ${MoneyBagFields} }
134
+ currentTotalPriceSet { ${MoneyBagFields} }
135
+ taxLines { ${TaxLineFields} }
136
+ shippingLines(first: 25, includeRemovals: true) { nodes { ${ShippingLineFields} } ${PageInfoFields} }
137
+ lineItems(first: 50) { nodes { ${LineItemFields} } ${PageInfoFields} }
138
+ `;
139
+
140
+ const orderConnectionQuery = (name: string, selection: string) => `#graphql
141
+ query ${name}($id: ID!, $first: Int!, $after: String) {
142
+ node: order(id: $id) {
143
+ connection: ${selection}
144
+ }
145
+ }
146
+ `;
147
+
148
+ export const OrderLineItemsQuery = orderConnectionQuery(
149
+ "AirfoilOrderLineItems",
150
+ `lineItems(first: $first, after: $after) { nodes { ${LineItemFields} } ${PageInfoFields} }`,
151
+ );
152
+
153
+ export const OrderShippingLinesQuery = orderConnectionQuery(
154
+ "AirfoilOrderShippingLines",
155
+ `shippingLines(first: $first, after: $after, includeRemovals: true) { nodes { ${ShippingLineFields} } ${PageInfoFields} }`,
156
+ );
157
+
158
+ export const OrderDiscountApplicationsQuery = orderConnectionQuery(
159
+ "AirfoilOrderDiscountApplications",
160
+ `discountApplications(first: $first, after: $after) { nodes { ${DiscountApplicationFields} } ${PageInfoFields} }`,
161
+ );
162
+
163
+ export const GraphQLLineItemsSchema = connection(
164
+ Schema.Struct({
165
+ id: Schema.String,
166
+ name: Schema.String,
167
+ title: Schema.String,
168
+ variantTitle: Schema.NullOr(Schema.String),
169
+ sku: Schema.NullOr(Schema.String),
170
+ vendor: Schema.NullOr(Schema.String),
171
+ product: idRef,
172
+ variant: idRef,
173
+ quantity: Schema.Int,
174
+ currentQuantity: Schema.Int,
175
+ taxable: Schema.Boolean,
176
+ requiresShipping: Schema.Boolean,
177
+ isGiftCard: Schema.Boolean,
178
+ originalUnitPriceSet: GraphQLMoneyBagSchema,
179
+ totalDiscountSet: GraphQLMoneyBagSchema,
180
+ taxLines: Schema.Array(GraphQLTaxLineSchema),
181
+ discountAllocations: Schema.Array(GraphQLDiscountAllocationSchema),
182
+ customAttributes: Schema.Array(GraphQLAttributeSchema),
183
+ }),
184
+ );
185
+
186
+ export const GraphQLShippingLinesSchema = connection(
187
+ Schema.Struct({
188
+ id: Schema.NullOr(Schema.String),
189
+ title: Schema.String,
190
+ code: Schema.NullOr(Schema.String),
191
+ source: Schema.NullOr(Schema.String),
192
+ carrierIdentifier: Schema.NullOr(Schema.String),
193
+ phone: Schema.NullOr(Schema.String),
194
+ isRemoved: Schema.Boolean,
195
+ originalPriceSet: GraphQLMoneyBagSchema,
196
+ discountedPriceSet: GraphQLMoneyBagSchema,
197
+ currentDiscountedPriceSet: GraphQLMoneyBagSchema,
198
+ taxLines: Schema.Array(GraphQLTaxLineSchema),
199
+ discountAllocations: Schema.Array(GraphQLDiscountAllocationSchema),
200
+ }),
201
+ );
202
+
203
+ const discountApplicationBase = {
204
+ index: Schema.Int,
205
+ allocationMethod: DiscountAllocationMethodSchema,
206
+ targetSelection: DiscountTargetSelectionSchema,
207
+ targetType: DiscountTargetTypeSchema,
208
+ value: Schema.Union([
209
+ Schema.Struct({ __typename: Schema.Literal("MoneyV2"), amount: Schema.String }),
210
+ Schema.Struct({
211
+ __typename: Schema.Literal("PricingPercentageValue"),
212
+ percentage: Schema.Number,
213
+ }),
214
+ ]),
215
+ };
216
+
217
+ export const GraphQLDiscountApplicationsSchema = connection(
218
+ Schema.Union([
219
+ Schema.Struct({
220
+ __typename: Schema.Literal("DiscountCodeApplication"),
221
+ code: Schema.String,
222
+ ...discountApplicationBase,
223
+ }),
224
+ Schema.Struct({
225
+ __typename: Schema.Literal("ManualDiscountApplication"),
226
+ title: Schema.String,
227
+ description: Schema.NullOr(Schema.String),
228
+ ...discountApplicationBase,
229
+ }),
230
+ Schema.Struct({
231
+ __typename: Schema.Literals(["AutomaticDiscountApplication", "ScriptDiscountApplication"]),
232
+ title: Schema.String,
233
+ ...discountApplicationBase,
234
+ }),
235
+ ]),
236
+ );
237
+
238
+ export const GraphQLOrderNodeSchema = Schema.Struct({
239
+ id: Schema.String,
240
+ legacyResourceId: Schema.String,
241
+ name: Schema.String,
242
+ email: Schema.NullOr(Schema.String),
243
+ phone: Schema.NullOr(Schema.String),
244
+ customer: idRef,
245
+ customerLocale: Schema.NullOr(Schema.String),
246
+ customerAcceptsMarketing: Schema.Boolean,
247
+ billingAddress: Schema.NullOr(GraphQLAddressSchema),
248
+ shippingAddress: Schema.NullOr(GraphQLAddressSchema),
249
+ note: Schema.NullOr(Schema.String),
250
+ customAttributes: Schema.Array(GraphQLAttributeSchema),
251
+ tags: Schema.Array(Schema.String),
252
+ confirmationNumber: Schema.NullOr(Schema.String),
253
+ poNumber: Schema.NullOr(Schema.String),
254
+ sourceName: Schema.NullOr(Schema.String),
255
+ sourceIdentifier: Schema.NullOr(Schema.String),
256
+ app: idRef,
257
+ paymentGatewayNames: Schema.Array(Schema.String),
258
+ test: Schema.Boolean,
259
+ taxesIncluded: Schema.Boolean,
260
+ taxExempt: Schema.Boolean,
261
+ dutiesIncluded: Schema.Boolean,
262
+ estimatedTaxes: Schema.Boolean,
263
+ totalWeight: Schema.NullOr(Schema.NumberFromString),
264
+ displayFinancialStatus: Schema.NullOr(OrderFinancialStatusSchema),
265
+ cancelReason: Schema.NullOr(OrderCancelReasonSchema),
266
+ cancelledAt: Schema.NullOr(Schema.DateFromString),
267
+ closedAt: Schema.NullOr(Schema.DateFromString),
268
+ processedAt: Schema.DateFromString,
269
+ createdAt: Schema.DateFromString,
270
+ updatedAt: Schema.DateFromString,
271
+ currencyCode: Schema.String,
272
+ presentmentCurrencyCode: Schema.String,
273
+ discountCodes: Schema.Array(Schema.String),
274
+ discountApplications: GraphQLDiscountApplicationsSchema,
275
+ subtotalPriceSet: Schema.NullOr(GraphQLMoneyBagSchema),
276
+ currentSubtotalPriceSet: GraphQLMoneyBagSchema,
277
+ totalDiscountsSet: Schema.NullOr(GraphQLMoneyBagSchema),
278
+ currentTotalDiscountsSet: GraphQLMoneyBagSchema,
279
+ totalShippingPriceSet: GraphQLMoneyBagSchema,
280
+ currentShippingPriceSet: GraphQLMoneyBagSchema,
281
+ totalTaxSet: Schema.NullOr(GraphQLMoneyBagSchema),
282
+ currentTotalTaxSet: GraphQLMoneyBagSchema,
283
+ originalTotalDutiesSet: Schema.NullOr(GraphQLMoneyBagSchema),
284
+ currentTotalDutiesSet: Schema.NullOr(GraphQLMoneyBagSchema),
285
+ totalPriceSet: GraphQLMoneyBagSchema,
286
+ currentTotalPriceSet: GraphQLMoneyBagSchema,
287
+ taxLines: Schema.Array(GraphQLTaxLineSchema),
288
+ shippingLines: GraphQLShippingLinesSchema,
289
+ lineItems: GraphQLLineItemsSchema,
290
+ });
291
+
292
+ export type GraphQLOrderNode = Schema.Schema.Type<typeof GraphQLOrderNodeSchema>;
293
+
294
+ const discountApplicationType = {
295
+ DiscountCodeApplication: "DISCOUNT_CODE",
296
+ ManualDiscountApplication: "MANUAL",
297
+ AutomaticDiscountApplication: "AUTOMATIC",
298
+ ScriptDiscountApplication: "SCRIPT",
299
+ } as const satisfies Record<string, DiscountApplicationType>;
300
+
301
+ export const fromOrderNode = (
302
+ node: GraphQLOrderNode,
303
+ nested: {
304
+ readonly discountApplications: Nodes<typeof GraphQLDiscountApplicationsSchema>;
305
+ readonly shippingLines: Nodes<typeof GraphQLShippingLinesSchema>;
306
+ readonly lineItems: Nodes<typeof GraphQLLineItemsSchema>;
307
+ },
308
+ ): Order => ({
309
+ id: node.id,
310
+ legacyResourceId: node.legacyResourceId,
311
+ name: node.name,
312
+ email: emptyText(node.email),
313
+ phone: emptyText(node.phone),
314
+ customerId: node.customer?.id ?? "",
315
+ customerLocale: emptyText(node.customerLocale),
316
+ customerAcceptsMarketing: node.customerAcceptsMarketing,
317
+ billingAddress: node.billingAddress ? fromGraphQL.address(node.billingAddress) : null,
318
+ shippingAddress: node.shippingAddress ? fromGraphQL.address(node.shippingAddress) : null,
319
+ note: emptyText(node.note),
320
+ customAttributes: node.customAttributes,
321
+ tags: node.tags,
322
+ confirmationNumber: emptyText(node.confirmationNumber),
323
+ poNumber: emptyText(node.poNumber),
324
+ sourceName: emptyText(node.sourceName),
325
+ sourceIdentifier: emptyText(node.sourceIdentifier),
326
+ appId: node.app?.id ?? "",
327
+ paymentGatewayNames: node.paymentGatewayNames,
328
+ test: node.test,
329
+ taxesIncluded: node.taxesIncluded,
330
+ taxExempt: node.taxExempt,
331
+ dutiesIncluded: node.dutiesIncluded,
332
+ estimatedTaxes: node.estimatedTaxes,
333
+ totalWeight: node.totalWeight,
334
+ displayFinancialStatus: node.displayFinancialStatus,
335
+ cancelReason: node.cancelReason,
336
+ cancelledAt: node.cancelledAt,
337
+ closedAt: node.closedAt,
338
+ processedAt: node.processedAt,
339
+ createdAt: node.createdAt,
340
+ updatedAt: node.updatedAt,
341
+ currencyCode: node.currencyCode,
342
+ presentmentCurrencyCode: node.presentmentCurrencyCode,
343
+ discountCodes: node.discountCodes,
344
+ discountApplications: nested.discountApplications.map(
345
+ (application): DiscountApplication => ({
346
+ index: application.index,
347
+ type: discountApplicationType[application.__typename],
348
+ code: application.__typename === "DiscountCodeApplication" ? application.code : null,
349
+ title: application.__typename === "DiscountCodeApplication" ? null : application.title,
350
+ description:
351
+ application.__typename === "ManualDiscountApplication" ? application.description : null,
352
+ allocationMethod: application.allocationMethod,
353
+ targetSelection: application.targetSelection,
354
+ targetType: application.targetType,
355
+ valueType: application.value.__typename === "MoneyV2" ? "FIXED_AMOUNT" : "PERCENTAGE",
356
+ value:
357
+ application.value.__typename === "MoneyV2"
358
+ ? normalizeAmount(application.value.amount)
359
+ : normalizeAmount(String(application.value.percentage)),
360
+ }),
361
+ ),
362
+ subtotalPriceSet: node.subtotalPriceSet ? fromGraphQL.money(node.subtotalPriceSet) : null,
363
+ currentSubtotalPriceSet: fromGraphQL.money(node.currentSubtotalPriceSet),
364
+ totalDiscountsSet: node.totalDiscountsSet ? fromGraphQL.money(node.totalDiscountsSet) : null,
365
+ currentTotalDiscountsSet: fromGraphQL.money(node.currentTotalDiscountsSet),
366
+ totalShippingPriceSet: fromGraphQL.money(node.totalShippingPriceSet),
367
+ currentShippingPriceSet: fromGraphQL.money(node.currentShippingPriceSet),
368
+ totalTaxSet: node.totalTaxSet ? fromGraphQL.money(node.totalTaxSet) : null,
369
+ currentTotalTaxSet: fromGraphQL.money(node.currentTotalTaxSet),
370
+ originalTotalDutiesSet: node.originalTotalDutiesSet
371
+ ? fromGraphQL.money(node.originalTotalDutiesSet)
372
+ : null,
373
+ currentTotalDutiesSet: node.currentTotalDutiesSet
374
+ ? fromGraphQL.money(node.currentTotalDutiesSet)
375
+ : null,
376
+ totalPriceSet: fromGraphQL.money(node.totalPriceSet),
377
+ currentTotalPriceSet: fromGraphQL.money(node.currentTotalPriceSet),
378
+ taxLines: node.taxLines.map(fromGraphQL.taxLine),
379
+ shippingLines: nested.shippingLines.map((line) => ({
380
+ id: line.id,
381
+ title: line.title,
382
+ code: line.code,
383
+ source: line.source,
384
+ carrierIdentifier: line.carrierIdentifier,
385
+ phone: line.phone,
386
+ isRemoved: line.isRemoved,
387
+ originalPriceSet: fromGraphQL.money(line.originalPriceSet),
388
+ discountedPriceSet: fromGraphQL.money(line.discountedPriceSet),
389
+ currentDiscountedPriceSet: fromGraphQL.money(line.currentDiscountedPriceSet),
390
+ taxLines: line.taxLines.map(fromGraphQL.taxLine),
391
+ discountAllocations: line.discountAllocations.map(fromGraphQL.discountAllocation),
392
+ })),
393
+ lineItems: nested.lineItems.map((item) => ({
394
+ id: item.id,
395
+ name: item.name,
396
+ title: item.title,
397
+ variantTitle: item.variantTitle,
398
+ sku: item.sku,
399
+ vendor: item.vendor,
400
+ productId: item.product?.id ?? null,
401
+ variantId: item.variant?.id ?? null,
402
+ quantity: item.quantity,
403
+ currentQuantity: item.currentQuantity,
404
+ taxable: item.taxable,
405
+ requiresShipping: item.requiresShipping,
406
+ isGiftCard: item.isGiftCard,
407
+ originalUnitPriceSet: fromGraphQL.money(item.originalUnitPriceSet),
408
+ totalDiscountSet: fromGraphQL.money(item.totalDiscountSet),
409
+ taxLines: item.taxLines.map(fromGraphQL.taxLine),
410
+ discountAllocations: item.discountAllocations.map(fromGraphQL.discountAllocation),
411
+ customAttributes: item.customAttributes,
412
+ })),
413
+ });
414
+
415
+ export const OrdersQuery = pageQuery("AirfoilOrders", "orders", OrderFields);
416
+
417
+ export const GraphQLOrdersDataSchema = Schema.Struct({
418
+ orders: connection(GraphQLOrderNodeSchema),
419
+ });
@@ -0,0 +1,180 @@
1
+ import { Iceberg } from "@useairfoil/connector-kit";
2
+ import * as Schema from "effect/Schema";
3
+
4
+ import { address, attributes, discountAllocations, field, moneyBag, taxLines } from "../shared";
5
+
6
+ export const OrderCancelReasonSchema = Schema.Literals([
7
+ "CUSTOMER",
8
+ "DECLINED",
9
+ "FRAUD",
10
+ "INVENTORY",
11
+ "STAFF",
12
+ "OTHER",
13
+ ]);
14
+
15
+ export const OrderFinancialStatusSchema = Schema.Literals([
16
+ "PENDING",
17
+ "AUTHORIZED",
18
+ "PARTIALLY_PAID",
19
+ "PARTIALLY_REFUNDED",
20
+ "VOIDED",
21
+ "PAID",
22
+ "REFUNDED",
23
+ "EXPIRED",
24
+ ]);
25
+
26
+ export const DiscountApplicationTypeSchema = Schema.Literals([
27
+ "DISCOUNT_CODE",
28
+ "MANUAL",
29
+ "AUTOMATIC",
30
+ "SCRIPT",
31
+ ]);
32
+
33
+ // Shopify deprecated ONE but still returns it for older orders.
34
+ export const DiscountAllocationMethodSchema = Schema.Literals(["ACROSS", "EACH", "ONE"]);
35
+
36
+ export const DiscountTargetSelectionSchema = Schema.Literals(["ALL", "ENTITLED", "EXPLICIT"]);
37
+
38
+ export const DiscountTargetTypeSchema = Schema.Literals(["LINE_ITEM", "SHIPPING_LINE"]);
39
+
40
+ export const DiscountValueTypeSchema = Schema.Literals(["PERCENTAGE", "FIXED_AMOUNT"]);
41
+
42
+ export const DiscountApplicationSchema = Schema.Struct({
43
+ index: Schema.Int.pipe(field(161, "Position used by discount allocations.")),
44
+ type: DiscountApplicationTypeSchema.pipe(field(162, "How the discount was applied.")),
45
+ code: Schema.NullOr(Schema.String).pipe(field(163, "Discount code.")),
46
+ title: Schema.NullOr(Schema.String).pipe(field(164, "Discount title.")),
47
+ description: Schema.NullOr(Schema.String).pipe(field(165, "Manual discount description.")),
48
+ allocationMethod: DiscountAllocationMethodSchema.pipe(field(166, "How the value is split.")),
49
+ targetSelection: DiscountTargetSelectionSchema.pipe(field(167, "Which lines are targeted.")),
50
+ targetType: DiscountTargetTypeSchema.pipe(field(168, "Kind of lines targeted.")),
51
+ valueType: DiscountValueTypeSchema.pipe(field(169, "Whether the value is a percent.")),
52
+ value: Schema.String.pipe(field(170, "Percent or amount in the customer currency.")),
53
+ });
54
+
55
+ export const ShippingLineSchema = Schema.Struct({
56
+ id: Schema.NullOr(Schema.String).pipe(field(501, "Unique shipping line identifier.")),
57
+ title: Schema.String.pipe(field(502, "Shipping method title.")),
58
+ code: Schema.NullOr(Schema.String).pipe(field(503, "Shipping rate code.")),
59
+ source: Schema.NullOr(Schema.String).pipe(field(504, "Source of the shipping rate.")),
60
+ carrierIdentifier: Schema.NullOr(Schema.String).pipe(field(505, "Carrier service identifier.")),
61
+ phone: Schema.NullOr(Schema.String).pipe(field(506, "Phone number for the shipping line.")),
62
+ isRemoved: Schema.Boolean.pipe(field(507, "Whether the line was removed by an edit.")),
63
+ originalPriceSet: moneyBag(520).pipe(field(508, "Price before discounts.")),
64
+ discountedPriceSet: moneyBag(530).pipe(field(509, "Price after discounts.")),
65
+ currentDiscountedPriceSet: moneyBag(540).pipe(
66
+ field(510, "Price after discounts, edits, and refunds."),
67
+ ),
68
+ taxLines: taxLines(550).pipe(field(511, "Taxes on the shipping line.")),
69
+ discountAllocations: discountAllocations(570).pipe(field(512, "Discounts on the line.")),
70
+ });
71
+
72
+ export const OrderLineItemSchema = Schema.Struct({
73
+ id: Schema.String.pipe(field(601, "Unique line item identifier.")),
74
+ name: Schema.String.pipe(field(602, "Product and variant name.")),
75
+ title: Schema.String.pipe(field(603, "Product title.")),
76
+ variantTitle: Schema.NullOr(Schema.String).pipe(field(604, "Variant title.")),
77
+ sku: Schema.NullOr(Schema.String).pipe(field(605, "Stock keeping unit.")),
78
+ vendor: Schema.NullOr(Schema.String).pipe(field(606, "Product vendor.")),
79
+ productId: Schema.NullOr(Schema.String).pipe(field(607, "Product identifier.")),
80
+ variantId: Schema.NullOr(Schema.String).pipe(field(608, "Product variant identifier.")),
81
+ quantity: Schema.Int.pipe(field(609, "Quantity when the order was placed.")),
82
+ currentQuantity: Schema.Int.pipe(field(610, "Quantity after removals and refunds.")),
83
+ taxable: Schema.Boolean.pipe(field(611, "Whether the line item is taxable.")),
84
+ requiresShipping: Schema.Boolean.pipe(field(612, "Whether the line item needs shipping.")),
85
+ isGiftCard: Schema.Boolean.pipe(field(613, "Whether the line item is a gift card.")),
86
+ originalUnitPriceSet: moneyBag(630).pipe(field(614, "Unit price before discounts.")),
87
+ totalDiscountSet: moneyBag(640).pipe(field(615, "Total discount on the line.")),
88
+ taxLines: taxLines(650).pipe(field(616, "Taxes on the line.")),
89
+ discountAllocations: discountAllocations(670).pipe(field(617, "Discounts on the line.")),
90
+ customAttributes: attributes(690).pipe(field(618, "Custom line properties.")),
91
+ });
92
+
93
+ export const OrderSchema = Schema.Struct({
94
+ id: Schema.String.pipe(field(1, "Unique order identifier.")),
95
+ legacyResourceId: Schema.String.pipe(field(2, "Numeric order identifier stored as text.")),
96
+ name: Schema.String.pipe(field(3, "Order name shown to the merchant.")),
97
+ email: Schema.NullOr(Schema.String).pipe(field(4, "Email used for the order.")),
98
+ phone: Schema.NullOr(Schema.String).pipe(field(5, "Phone used for the order.")),
99
+ customerId: Schema.NullOr(Schema.String).pipe(field(6, "Customer identifier.")),
100
+ customerLocale: Schema.NullOr(Schema.String).pipe(field(7, "Customer language.")),
101
+ customerAcceptsMarketing: Schema.Boolean.pipe(field(8, "Whether the buyer accepts marketing.")),
102
+ billingAddress: Schema.NullOr(address(100)).pipe(field(9, "Billing address.")),
103
+ shippingAddress: Schema.NullOr(address(120)).pipe(field(10, "Shipping address.")),
104
+ note: Schema.NullOr(Schema.String).pipe(field(11, "Order note.")),
105
+ customAttributes: attributes(140).pipe(field(12, "Custom order attributes.")),
106
+ tags: Schema.Array(Schema.String.annotate({ fieldId: 150 })).pipe(
107
+ field(13, "Tags added to the order."),
108
+ ),
109
+ confirmationNumber: Schema.NullOr(Schema.String).pipe(field(14, "Confirmation number.")),
110
+ poNumber: Schema.NullOr(Schema.String).pipe(field(15, "Purchase order number.")),
111
+ sourceName: Schema.NullOr(Schema.String).pipe(field(16, "Channel that created the order.")),
112
+ sourceIdentifier: Schema.NullOr(Schema.String).pipe(field(17, "Identifier from the source.")),
113
+ appId: Schema.NullOr(Schema.String).pipe(field(18, "App that created the order.")),
114
+ paymentGatewayNames: Schema.Array(Schema.String.annotate({ fieldId: 152 })).pipe(
115
+ field(19, "Payment gateways used."),
116
+ ),
117
+ test: Schema.Boolean.pipe(field(20, "Whether the order is a test order.")),
118
+ taxesIncluded: Schema.Boolean.pipe(field(21, "Whether prices include taxes.")),
119
+ taxExempt: Schema.Boolean.pipe(field(22, "Whether the order is exempt from tax.")),
120
+ dutiesIncluded: Schema.Boolean.pipe(field(23, "Whether prices include duties.")),
121
+ estimatedTaxes: Schema.Boolean.pipe(field(24, "Whether taxes are estimates.")),
122
+ totalWeight: Schema.NullOr(Schema.Int).pipe(field(25, "Total weight in grams.")),
123
+ displayFinancialStatus: Schema.NullOr(OrderFinancialStatusSchema).pipe(
124
+ field(26, "Payment status of the order."),
125
+ ),
126
+ cancelReason: Schema.NullOr(OrderCancelReasonSchema).pipe(
127
+ field(27, "Reason the order was cancelled."),
128
+ ),
129
+ cancelledAt: Schema.NullOr(Schema.Date).pipe(field(28, "Time when the order was cancelled.")),
130
+ closedAt: Schema.NullOr(Schema.Date).pipe(field(29, "Time when the order was closed.")),
131
+ processedAt: Schema.Date.pipe(field(30, "Time when the order was processed.")),
132
+ createdAt: Schema.Date.pipe(field(31, "Time when the order was created.")),
133
+ updatedAt: Schema.Date.pipe(field(32, "Time when the order was last changed.")),
134
+ currencyCode: Schema.String.pipe(field(33, "Shop currency code.")),
135
+ presentmentCurrencyCode: Schema.String.pipe(field(34, "Customer currency code.")),
136
+ discountCodes: Schema.Array(Schema.String.annotate({ fieldId: 151 })).pipe(
137
+ field(35, "Discount codes used."),
138
+ ),
139
+ discountApplications: Schema.Array(DiscountApplicationSchema.annotate({ fieldId: 160 })).pipe(
140
+ field(36, "Discounts applied to the order."),
141
+ ),
142
+ subtotalPriceSet: Schema.NullOr(moneyBag(200)).pipe(
143
+ field(37, "Subtotal when the order was placed."),
144
+ ),
145
+ currentSubtotalPriceSet: moneyBag(210).pipe(field(38, "Subtotal after edits and refunds.")),
146
+ totalDiscountsSet: Schema.NullOr(moneyBag(220)).pipe(
147
+ field(39, "Discounts when the order was placed."),
148
+ ),
149
+ currentTotalDiscountsSet: moneyBag(230).pipe(field(40, "Discounts after edits and refunds.")),
150
+ totalShippingPriceSet: moneyBag(240).pipe(field(41, "Shipping when the order was placed.")),
151
+ currentShippingPriceSet: moneyBag(250).pipe(field(42, "Shipping after edits and refunds.")),
152
+ totalTaxSet: Schema.NullOr(moneyBag(260)).pipe(field(43, "Tax when the order was placed.")),
153
+ currentTotalTaxSet: moneyBag(270).pipe(field(44, "Tax after edits and refunds.")),
154
+ originalTotalDutiesSet: Schema.NullOr(moneyBag(280)).pipe(
155
+ field(45, "Duties when the order was placed."),
156
+ ),
157
+ currentTotalDutiesSet: Schema.NullOr(moneyBag(290)).pipe(
158
+ field(46, "Duties after edits and refunds."),
159
+ ),
160
+ totalPriceSet: moneyBag(300).pipe(field(47, "Total when the order was placed.")),
161
+ currentTotalPriceSet: moneyBag(310).pipe(field(48, "Total after edits and refunds.")),
162
+ taxLines: taxLines(400).pipe(field(49, "Taxes when the order was placed.")),
163
+ shippingLines: Schema.Array(ShippingLineSchema.annotate({ fieldId: 500 })).pipe(
164
+ field(50, "Shipping lines, including removed ones."),
165
+ ),
166
+ lineItems: Schema.Array(OrderLineItemSchema.annotate({ fieldId: 600 })).pipe(
167
+ field(51, "Line items in the order."),
168
+ ),
169
+ _deleted: Schema.optional(Schema.Boolean).pipe(field(52, "Whether the order was deleted.")),
170
+ })
171
+ .annotate({
172
+ description: "Orders in a Shopify store.",
173
+ })
174
+ .pipe(Iceberg.identifier("id"));
175
+
176
+ export type Order = Schema.Schema.Type<typeof OrderSchema>;
177
+
178
+ export type DiscountApplication = Schema.Schema.Type<typeof DiscountApplicationSchema>;
179
+
180
+ export type DiscountApplicationType = Schema.Schema.Type<typeof DiscountApplicationTypeSchema>;