@drawbridge/drawbridge-utils 0.0.175 → 0.0.177
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/dist/admin-B9ZaLvan.d.cts +697 -0
- package/dist/admin-C3HtEM6h.d.ts +697 -0
- package/dist/billing-Bc4yo9XG.d.cts +175 -0
- package/dist/billing-mNsKflmQ.d.ts +175 -0
- package/dist/billing.d.cts +1 -1
- package/dist/billing.d.ts +1 -1
- package/dist/connections/index.cjs +5928 -1920
- package/dist/connections/index.d.cts +20 -9163
- package/dist/connections/index.d.ts +20 -9163
- package/dist/connections/index.js +5917 -1921
- package/dist/connections/oauth.cjs +4 -4
- package/dist/connections/oauth.d.cts +10 -8
- package/dist/connections/oauth.d.ts +10 -8
- package/dist/connections/oauth.js +4 -4
- package/dist/features.cjs +10260 -42
- package/dist/features.d.cts +55 -42
- package/dist/features.d.ts +55 -42
- package/dist/features.js +10254 -42
- package/dist/http.cjs +10 -1
- package/dist/http.d.cts +10 -1
- package/dist/http.d.ts +10 -1
- package/dist/http.js +10 -1
- package/dist/index-B546oDNo.d.ts +13809 -0
- package/dist/index-C59xHago.d.cts +13809 -0
- package/dist/oauth/index.d.cts +1 -1
- package/dist/oauth/index.d.ts +1 -1
- package/dist/oauth-BJDh0sdM.d.cts +527 -0
- package/dist/oauth-DveZMLHx.d.ts +527 -0
- package/dist/partner-BOZltuh2.d.ts +94 -0
- package/dist/partner-ed2OfW1J.d.cts +94 -0
- package/dist/plans.cjs +10256 -51
- package/dist/plans.d.cts +37 -10
- package/dist/plans.d.ts +37 -10
- package/dist/plans.js +10262 -51
- package/dist/pricing.cjs +10401 -209
- package/dist/pricing.d.cts +34 -17
- package/dist/pricing.d.ts +34 -17
- package/dist/pricing.js +10407 -209
- package/dist/providers.cjs +5433 -1755
- package/dist/providers.d.cts +13 -15
- package/dist/providers.d.ts +13 -15
- package/dist/providers.js +5436 -1752
- package/dist/sendgrid.cjs +10 -1
- package/dist/sendgrid.js +10 -1
- package/dist/shopify/admin.cjs +562 -0
- package/dist/shopify/admin.d.cts +3 -0
- package/dist/shopify/admin.d.ts +3 -0
- package/dist/shopify/admin.js +528 -0
- package/dist/shopify/billing.cjs +166 -0
- package/dist/shopify/billing.d.cts +3 -0
- package/dist/shopify/billing.d.ts +3 -0
- package/dist/shopify/billing.js +140 -0
- package/dist/shopify/constants.cjs +63 -0
- package/dist/shopify/constants.d.cts +58 -0
- package/dist/shopify/constants.d.ts +58 -0
- package/dist/shopify/constants.js +32 -0
- package/dist/shopify/oauth.cjs +509 -0
- package/dist/shopify/oauth.d.cts +7 -0
- package/dist/shopify/oauth.d.ts +7 -0
- package/dist/shopify/oauth.js +466 -0
- package/dist/shopify/partner.cjs +156 -0
- package/dist/shopify/partner.d.cts +3 -0
- package/dist/shopify/partner.d.ts +3 -0
- package/dist/shopify/partner.js +130 -0
- package/dist/shopify/storefront.cjs +611 -0
- package/dist/shopify/storefront.d.cts +3 -0
- package/dist/shopify/storefront.d.ts +3 -0
- package/dist/shopify/storefront.js +576 -0
- package/dist/storefront-C8FKOGeD.d.cts +659 -0
- package/dist/storefront-DJFGLqPl.d.ts +659 -0
- package/dist/twilio.cjs +10 -1
- package/dist/twilio.js +10 -1
- 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
|
+
};
|