@drawbridge/drawbridge-utils 0.0.176 → 0.0.178

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 (69) hide show
  1. package/dist/admin-B9ZaLvan.d.cts +697 -0
  2. package/dist/admin-C3HtEM6h.d.ts +697 -0
  3. package/dist/billing-Bc4yo9XG.d.cts +175 -0
  4. package/dist/billing-mNsKflmQ.d.ts +175 -0
  5. package/dist/billing.d.cts +1 -1
  6. package/dist/billing.d.ts +1 -1
  7. package/dist/connections/index.cjs +3391 -271
  8. package/dist/connections/index.d.cts +13 -4
  9. package/dist/connections/index.d.ts +13 -4
  10. package/dist/connections/index.js +3388 -270
  11. package/dist/features.cjs +3080 -241
  12. package/dist/features.d.cts +13 -4
  13. package/dist/features.d.ts +13 -4
  14. package/dist/features.js +3120 -275
  15. package/dist/http.cjs +10 -1
  16. package/dist/http.d.cts +10 -1
  17. package/dist/http.d.ts +10 -1
  18. package/dist/http.js +10 -1
  19. package/dist/{index-qY18QITf.d.cts → index-C2rxasGZ.d.cts} +2670 -354
  20. package/dist/{index-B8JhYfvU.d.ts → index-DOYCXtd7.d.ts} +2670 -354
  21. package/dist/oauth/index.d.cts +1 -1
  22. package/dist/oauth/index.d.ts +1 -1
  23. package/dist/oauth-BJDh0sdM.d.cts +527 -0
  24. package/dist/oauth-DveZMLHx.d.ts +527 -0
  25. package/dist/partner-BOZltuh2.d.ts +94 -0
  26. package/dist/partner-ed2OfW1J.d.cts +94 -0
  27. package/dist/plans.cjs +3079 -240
  28. package/dist/plans.d.cts +13 -4
  29. package/dist/plans.d.ts +13 -4
  30. package/dist/plans.js +3120 -275
  31. package/dist/pricing.cjs +3112 -273
  32. package/dist/pricing.d.cts +13 -4
  33. package/dist/pricing.d.ts +13 -4
  34. package/dist/pricing.js +3117 -272
  35. package/dist/providers.cjs +3082 -262
  36. package/dist/providers.d.cts +12 -3
  37. package/dist/providers.d.ts +12 -3
  38. package/dist/providers.js +3086 -260
  39. package/dist/sendgrid.cjs +10 -1
  40. package/dist/sendgrid.js +10 -1
  41. package/dist/shopify/admin.cjs +562 -0
  42. package/dist/shopify/admin.d.cts +3 -0
  43. package/dist/shopify/admin.d.ts +3 -0
  44. package/dist/shopify/admin.js +528 -0
  45. package/dist/shopify/billing.cjs +166 -0
  46. package/dist/shopify/billing.d.cts +3 -0
  47. package/dist/shopify/billing.d.ts +3 -0
  48. package/dist/shopify/billing.js +140 -0
  49. package/dist/shopify/constants.cjs +63 -0
  50. package/dist/shopify/constants.d.cts +58 -0
  51. package/dist/shopify/constants.d.ts +58 -0
  52. package/dist/shopify/constants.js +32 -0
  53. package/dist/shopify/oauth.cjs +509 -0
  54. package/dist/shopify/oauth.d.cts +7 -0
  55. package/dist/shopify/oauth.d.ts +7 -0
  56. package/dist/shopify/oauth.js +466 -0
  57. package/dist/shopify/partner.cjs +156 -0
  58. package/dist/shopify/partner.d.cts +3 -0
  59. package/dist/shopify/partner.d.ts +3 -0
  60. package/dist/shopify/partner.js +130 -0
  61. package/dist/shopify/storefront.cjs +611 -0
  62. package/dist/shopify/storefront.d.cts +3 -0
  63. package/dist/shopify/storefront.d.ts +3 -0
  64. package/dist/shopify/storefront.js +576 -0
  65. package/dist/storefront-C8FKOGeD.d.cts +659 -0
  66. package/dist/storefront-DJFGLqPl.d.ts +659 -0
  67. package/dist/twilio.cjs +10 -1
  68. package/dist/twilio.js +10 -1
  69. package/package.json +98 -68
@@ -0,0 +1,130 @@
1
+ // lib/http.js
2
+ var DEFAULT_TIMEOUT_MS = 15e3;
3
+ var request = async ({
4
+ body,
5
+ // THE TRANSPORT, injectable and defaulted to the real one.
6
+ //
7
+ // Every other vendor client in this package takes a `fetcher` — it is how
8
+ // klaviyo, mailchimp and attentive are tested without a network, and it is a
9
+ // declared HOOK_OPTION. The Shopify client had no seam at all, so the only way
10
+ // to test a hook that used it was to inject the whole SDK namespace; that
11
+ // injection existed to work around an import cycle, and when the cycle went
12
+ // the tests lost their only hold. This is the seam they should have had.
13
+ fetcher = fetch,
14
+ headers = {},
15
+ method = "GET",
16
+ query,
17
+ timeout = DEFAULT_TIMEOUT_MS,
18
+ type = "json",
19
+ url
20
+ }) => {
21
+ const fullUrl = new URL(url);
22
+ if (query) {
23
+ Object.entries(query).forEach(([k, v]) => fullUrl.searchParams.set(k, v));
24
+ }
25
+ ;
26
+ const isForm = type === "form";
27
+ const response = await fetcher(fullUrl.toString(), {
28
+ method,
29
+ headers: {
30
+ "Content-Type": isForm ? "application/x-www-form-urlencoded" : "application/json",
31
+ ...headers
32
+ },
33
+ signal: AbortSignal.timeout(timeout),
34
+ ...body !== void 0 && {
35
+ body: isForm ? new URLSearchParams(body).toString() : JSON.stringify(body)
36
+ }
37
+ });
38
+ if (!response.ok) {
39
+ const text2 = await response.text().catch(() => "");
40
+ const error = new Error(text2 || response.statusText);
41
+ error.status = response.status;
42
+ throw error;
43
+ }
44
+ ;
45
+ const text = await response.text();
46
+ try {
47
+ return text ? JSON.parse(text) : null;
48
+ } catch {
49
+ return null;
50
+ }
51
+ };
52
+
53
+ // lib/shopify/constants.js
54
+ var REFRESH_TOKEN_LIFETIME_MS = 90 * 24 * 60 * 60 * 1e3;
55
+ var ACCESS_TOKEN_REFRESH_BUFFER_MS = 5 * 60 * 1e3;
56
+ var PARTNER_API_VERSION = process.env.SHOPIFY_PARTNER_API_VERSION || "2026-07";
57
+
58
+ // lib/shopify/partner.js
59
+ var PARTNER_API = "https://partners.shopify.com";
60
+ var getUsageChargeEvents = async ({ fetcher, appId, first = 10, occurredAtMin, organizationId, partnerToken, shopId }) => {
61
+ var _a, _b, _c;
62
+ if (!partnerToken || !organizationId || !appId) {
63
+ throw new Error("getUsageChargeEvents requires partnerToken, organizationId, and appId");
64
+ }
65
+ ;
66
+ const data = await request({
67
+ fetcher,
68
+ method: "POST",
69
+ url: PARTNER_API + "/" + organizationId + "/api/" + PARTNER_API_VERSION + "/graphql.json",
70
+ headers: {
71
+ "X-Shopify-Access-Token": partnerToken
72
+ },
73
+ body: {
74
+ query: `query usageCharges( $filter : EventFilterInput!, $first : Int! ) {
75
+ events( filter : $filter, orderBy : OCCURRED_AT_DESC, first : $first ) {
76
+ edges {
77
+ node {
78
+ id
79
+ occurredAt
80
+ eventType
81
+ shop { id myshopifyDomain }
82
+ ... on Charge {
83
+ chargeId
84
+ chargeType
85
+ amount { amount currencyCode }
86
+ usageQuantity
87
+ planHandle
88
+ description
89
+ }
90
+ }
91
+ }
92
+ pageInfo { hasNextPage endCursor }
93
+ }
94
+ }`,
95
+ variables: {
96
+ filter: {
97
+ eventTypes: ["CHARGE_USAGE"],
98
+ subjectId: String(appId),
99
+ ...occurredAtMin && { occurredAtMin },
100
+ ...shopId && { shopId: String(shopId) }
101
+ },
102
+ first
103
+ }
104
+ }
105
+ });
106
+ if ((_a = data == null ? void 0 : data.errors) == null ? void 0 : _a.length) {
107
+ throw new Error("Shopify partner events query failed: " + data.errors.map((entry) => entry.message).join("; "));
108
+ }
109
+ ;
110
+ return (((_c = (_b = data == null ? void 0 : data.data) == null ? void 0 : _b.events) == null ? void 0 : _c.edges) || []).map((edge) => {
111
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j;
112
+ return {
113
+ amount: ((_a2 = edge.node) == null ? void 0 : _a2.amount) || null,
114
+ chargeId: ((_b2 = edge.node) == null ? void 0 : _b2.chargeId) || null,
115
+ // USAGE vs the recurring plan charge an approval emits — the
116
+ // disambiguator callers filter on.
117
+ chargeType: ((_c2 = edge.node) == null ? void 0 : _c2.chargeType) || null,
118
+ description: ((_d = edge.node) == null ? void 0 : _d.description) || null,
119
+ eventType: ((_e = edge.node) == null ? void 0 : _e.eventType) || null,
120
+ id: ((_f = edge.node) == null ? void 0 : _f.id) || null,
121
+ occurredAt: ((_g = edge.node) == null ? void 0 : _g.occurredAt) || null,
122
+ planHandle: ((_h = edge.node) == null ? void 0 : _h.planHandle) || null,
123
+ shop: ((_i = edge.node) == null ? void 0 : _i.shop) || null,
124
+ usageQuantity: ((_j = edge.node) == null ? void 0 : _j.usageQuantity) ?? null
125
+ };
126
+ });
127
+ };
128
+ export {
129
+ getUsageChargeEvents
130
+ };