@drawbridge/drawbridge-utils 0.0.151 → 0.0.153
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/connections/index.cjs +312 -112
- package/dist/connections/index.d.cts +471 -135
- package/dist/connections/index.d.ts +471 -135
- package/dist/connections/index.js +309 -111
- package/dist/providers.cjs +323 -117
- package/dist/providers.d.cts +37 -15
- package/dist/providers.d.ts +37 -15
- package/dist/providers.js +320 -116
- package/package.json +1 -1
package/dist/providers.js
CHANGED
|
@@ -721,10 +721,16 @@ var attentive_default2 = {
|
|
|
721
721
|
// `redact` marks a secret — never returned by the api, and blank on save means
|
|
722
722
|
// keep the stored value. `required` drives the live check.
|
|
723
723
|
provider: {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
724
|
+
vendors: {
|
|
725
|
+
attentive: {
|
|
726
|
+
fields: [
|
|
727
|
+
{ input: "text", key: "clientId", credential: "ATTENTIVE_OAUTH_CLIENT_ID", label: "Client ID", message: "From our app's registration in the Attentive developer portal.", required: true },
|
|
728
|
+
{ input: "password", key: "clientSecret", credential: "ATTENTIVE_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID in the Attentive developer portal.", redact: true, required: true }
|
|
729
|
+
],
|
|
730
|
+
icon: attentive_default,
|
|
731
|
+
name: "Attentive"
|
|
732
|
+
}
|
|
733
|
+
}
|
|
728
734
|
},
|
|
729
735
|
requires: [
|
|
730
736
|
"ATTENTIVE_OAUTH_CLIENT_ID",
|
|
@@ -990,6 +996,43 @@ var drawbridge_default = `<svg width="500" height="500" viewBox="0 0 500 500" fi
|
|
|
990
996
|
</defs>
|
|
991
997
|
</svg>`;
|
|
992
998
|
|
|
999
|
+
// lib/connections/icons/hubspot.js
|
|
1000
|
+
var hubspot_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1001
|
+
<rect width="500" height="500" fill="#FF7A59"/>
|
|
1002
|
+
<circle cx="290" cy="290" r="78" stroke="white" stroke-width="30"/>
|
|
1003
|
+
<circle cx="290" cy="290" r="18" fill="white"/>
|
|
1004
|
+
<path d="M290 212V150" stroke="white" stroke-width="30" stroke-linecap="round"/>
|
|
1005
|
+
<circle cx="290" cy="125" r="28" fill="white"/>
|
|
1006
|
+
<path d="M270 137L172 96" stroke="white" stroke-width="22" stroke-linecap="round"/>
|
|
1007
|
+
<circle cx="160" cy="91" r="20" fill="white"/>
|
|
1008
|
+
<path d="M233 347L184 396" stroke="white" stroke-width="26" stroke-linecap="round"/>
|
|
1009
|
+
<circle cx="172" cy="408" r="22" fill="white"/>
|
|
1010
|
+
</svg>`;
|
|
1011
|
+
|
|
1012
|
+
// lib/connections/icons/sendgrid.js
|
|
1013
|
+
var sendgrid_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1014
|
+
<rect width="500" height="500" fill="#F1FAFF"/>
|
|
1015
|
+
<g clip-path="url(#clip0_1011_2743)">
|
|
1016
|
+
<path d="M366.676 134.534V289.172H289.203V366.487H134.258L134.258 289.171L134.256 289.172V211.851H211.729V134.534H366.676Z" fill="#9DD6E3"/>
|
|
1017
|
+
<path d="M134.258 366.488H211.731V289.169H134.258V366.488Z" fill="#3F72AB"/>
|
|
1018
|
+
<path d="M289.203 289.172H366.677V211.852H289.203V289.172Z" fill="#00A9D1"/>
|
|
1019
|
+
<path d="M211.729 211.853H289.202V134.534H211.729V211.853Z" fill="#00A9D1"/>
|
|
1020
|
+
<path d="M211.729 289.17H289.202V211.852H211.729V289.17Z" fill="#2191C4"/>
|
|
1021
|
+
<path d="M289.203 211.853H366.677V134.534H289.203V211.853Z" fill="#3F72AB"/>
|
|
1022
|
+
</g>
|
|
1023
|
+
<defs>
|
|
1024
|
+
<clipPath id="clip0_1011_2743">
|
|
1025
|
+
<rect width="232.42" height="231.956" fill="white" transform="translate(134.256 134.534)"/>
|
|
1026
|
+
</clipPath>
|
|
1027
|
+
</defs>
|
|
1028
|
+
</svg>`;
|
|
1029
|
+
|
|
1030
|
+
// lib/connections/icons/twilio.js
|
|
1031
|
+
var twilio_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1032
|
+
<rect width="500" height="500" fill="#F22F46"/>
|
|
1033
|
+
<path d="M250 134.954C186.341 134.954 134.954 186.341 134.954 250C134.954 313.659 186.341 365.047 250 365.047C313.659 365.047 365.047 313.659 365.047 250C365.047 186.341 313.659 134.954 250 134.954ZM250 334.368C203.215 334.368 165.633 296.786 165.633 250C165.633 203.215 203.215 165.633 250 165.633C296.786 165.633 334.368 203.215 334.368 250C334.368 296.786 296.786 334.368 250 334.368ZM302.155 221.622C302.155 234.661 291.417 245.399 278.378 245.399C265.34 245.399 254.602 234.661 254.602 221.622C254.602 208.584 265.34 197.846 278.378 197.846C291.417 197.846 302.155 208.584 302.155 221.622ZM302.155 278.378C302.155 291.417 291.417 302.155 278.378 302.155C265.34 302.155 254.602 291.417 254.602 278.378C254.602 265.34 265.34 254.602 278.378 254.602C291.417 254.602 302.155 265.34 302.155 278.378ZM245.399 278.378C245.399 291.417 234.661 302.155 221.622 302.155C208.584 302.155 197.846 291.417 197.846 278.378C197.846 265.34 208.584 254.602 221.622 254.602C234.661 254.602 245.399 265.34 245.399 278.378ZM245.399 221.622C245.399 234.661 234.661 245.399 221.622 245.399C208.584 245.399 197.846 234.661 197.846 221.622C197.846 208.584 208.584 197.846 221.622 197.846C234.661 197.846 245.399 208.584 245.399 221.622Z" fill="white"/>
|
|
1034
|
+
</svg>`;
|
|
1035
|
+
|
|
993
1036
|
// lib/transactions.js
|
|
994
1037
|
import { currentTraceId } from "@drawbridge/drawbridge-telemetry";
|
|
995
1038
|
|
|
@@ -2156,37 +2199,56 @@ var drawbridge_default2 = {
|
|
|
2156
2199
|
//
|
|
2157
2200
|
// They belong on THIS manifest because this is the connection that sends: the
|
|
2158
2201
|
// email, sms and segment hooks below are the only things that spend them, and
|
|
2159
|
-
// a private connection is still where a vendor fact lives.
|
|
2202
|
+
// a private connection is still where a vendor fact lives. They are THREE
|
|
2203
|
+
// VENDORS, not one, and each is its own row and its own admin card — so
|
|
2204
|
+
// SendGrid reads live on a deployment that never configured Twilio, instead
|
|
2205
|
+
// of one card for all three that could only ever be as live as its weakest.
|
|
2160
2206
|
//
|
|
2161
2207
|
// UNLIKE every public vendor, none of these appear in `requires` — see the
|
|
2162
2208
|
// comment there. Availability and configuration are different questions, and a
|
|
2163
2209
|
// missing CRM token must not take every base workflow step away.
|
|
2210
|
+
//
|
|
2211
|
+
// ponytail: the field keys keep the names they had on the shared row
|
|
2212
|
+
// (smsSid, hubspotToken) so the readers destructuring vendorSettings() did
|
|
2213
|
+
// not move. Rename them to sid/token when those readers are next touched.
|
|
2164
2214
|
provider: {
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
// mail are email. Requiring Twilio here made the whole drawbridge
|
|
2179
|
-
// provider read not-live on a deployment that never sends SMS, over a
|
|
2180
|
-
// channel it was not using.
|
|
2181
|
-
//
|
|
2215
|
+
vendors: {
|
|
2216
|
+
sendgrid: {
|
|
2217
|
+
fields: [
|
|
2218
|
+
{ input: "email", key: "accountSender", credential: "SENDGRID_FROM_ADDRESS", label: "Account sender", message: "Verification codes and security alerts send from here.", required: true },
|
|
2219
|
+
{ input: "password", key: "apiKey", credential: "SENDGRID_API_KEY", label: "SendGrid API key", message: "SendGrid dashboard, Settings, API Keys \u2014 full access for sends.", redact: true, required: true },
|
|
2220
|
+
// Optional: SENDGRID_SEND_FROM_ADDRESS is not boot-required in sync
|
|
2221
|
+
// either. Unset, it degrades to the account sender rather than
|
|
2222
|
+
// refusing to start.
|
|
2223
|
+
{ input: "email", key: "leadSender", credential: "SENDGRID_SEND_FROM_ADDRESS", label: "Lead sender", message: "The default for lead-facing mail when a merchant has not verified their own domain." }
|
|
2224
|
+
],
|
|
2225
|
+
icon: sendgrid_default,
|
|
2226
|
+
name: "SendGrid"
|
|
2227
|
+
},
|
|
2182
2228
|
// Missing, SMS is LOCKED DOWN rather than broken: every send path
|
|
2183
2229
|
// refuses cleanly (queue/notification.js cancels, the otc stream skips
|
|
2184
2230
|
// and logs), the number-purchase routes deny, and identityDefaults.sms
|
|
2185
|
-
// hides the org's SMS settings entirely.
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2231
|
+
// hides the org's SMS settings entirely. The card reads not live, which
|
|
2232
|
+
// is the truth about Twilio and says nothing about email.
|
|
2233
|
+
twilio: {
|
|
2234
|
+
fields: [
|
|
2235
|
+
{ input: "text", key: "smsFrom", credential: "TWILIO_ACCOUNT_FROM", label: "SMS number", message: "Without Twilio credentials, SMS is disabled across the platform.", required: true },
|
|
2236
|
+
{ input: "password", key: "smsSid", credential: "TWILIO_ACCOUNT_SID", label: "Twilio account SID", message: "Twilio console home \u2014 the AC\u2026 identifier on the account dashboard.", redact: true, required: true },
|
|
2237
|
+
{ input: "password", key: "smsToken", credential: "TWILIO_AUTH_TOKEN", label: "Twilio auth token", message: "Beside the account SID on the Twilio console dashboard.", redact: true, required: true }
|
|
2238
|
+
],
|
|
2239
|
+
icon: twilio_default,
|
|
2240
|
+
name: "Twilio"
|
|
2241
|
+
},
|
|
2242
|
+
// The CRM sync is best-effort internal tooling and no-ops without a
|
|
2243
|
+
// token. Not live here costs nothing a merchant can see.
|
|
2244
|
+
hubspot: {
|
|
2245
|
+
fields: [
|
|
2246
|
+
{ input: "password", key: "hubspotToken", credential: "HUBSPOT_ACCESS_TOKEN", label: "HubSpot access token", message: "Drawbridge's own CRM portal. Internal \u2014 no merchant sees this.", redact: true, required: true }
|
|
2247
|
+
],
|
|
2248
|
+
icon: hubspot_default,
|
|
2249
|
+
name: "HubSpot"
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2190
2252
|
},
|
|
2191
2253
|
// NOTHING, and HUBSPOT_ACCESS_TOKEN in particular must not be here.
|
|
2192
2254
|
//
|
|
@@ -2772,12 +2834,20 @@ var klaviyo_default2 = {
|
|
|
2772
2834
|
// DRAWBRIDGE'S OWN CREDENTIALS for this vendor, as opposed to a merchant's —
|
|
2773
2835
|
// what an admin types on the provider screen. Declared here rather than in a
|
|
2774
2836
|
// table in lib/providers.js, so a vendor's credentials sit beside the
|
|
2775
|
-
// `requires` that names the same variables.
|
|
2837
|
+
// `requires` that names the same variables. Keyed by the VENDOR that holds
|
|
2838
|
+
// them — here the vendor and the connection are the same thing, which is not
|
|
2839
|
+
// true of every manifest.
|
|
2776
2840
|
provider: {
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2841
|
+
vendors: {
|
|
2842
|
+
klaviyo: {
|
|
2843
|
+
fields: [
|
|
2844
|
+
{ input: "text", key: "clientId", credential: "KLAVIYO_OAUTH_CLIENT_ID", label: "Client ID", message: "From our app in the Klaviyo developer portal (developers.klaviyo.com).", required: true },
|
|
2845
|
+
{ input: "password", key: "clientSecret", credential: "KLAVIYO_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID on the Klaviyo app.", redact: true, required: true }
|
|
2846
|
+
],
|
|
2847
|
+
icon: klaviyo_default,
|
|
2848
|
+
name: "Klaviyo"
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2781
2851
|
},
|
|
2782
2852
|
requires: [
|
|
2783
2853
|
"KLAVIYO_OAUTH_CLIENT_ID",
|
|
@@ -3120,10 +3190,16 @@ var mailchimp_default2 = {
|
|
|
3120
3190
|
// what an admin types on the provider screen, beside the `requires` naming the
|
|
3121
3191
|
// same variables.
|
|
3122
3192
|
provider: {
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3193
|
+
vendors: {
|
|
3194
|
+
mailchimp: {
|
|
3195
|
+
fields: [
|
|
3196
|
+
{ input: "text", key: "clientId", credential: "MAILCHIMP_OAUTH_CLIENT_ID", label: "Client ID", message: "From our registered app \u2014 Mailchimp account, Extras, Registered apps.", required: true },
|
|
3197
|
+
{ input: "password", key: "clientSecret", credential: "MAILCHIMP_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID on the registered app.", redact: true, required: true }
|
|
3198
|
+
],
|
|
3199
|
+
icon: mailchimp_default,
|
|
3200
|
+
name: "Mailchimp"
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3127
3203
|
},
|
|
3128
3204
|
// The OAuth client this deployment registered. Without both, the vendor drops
|
|
3129
3205
|
// out of availableConnections rather than offering a Connect button that
|
|
@@ -4028,7 +4104,7 @@ var shopify_default2 = {
|
|
|
4028
4104
|
// against the ones the app now needs, and queues a webhook
|
|
4029
4105
|
// reconciliation.
|
|
4030
4106
|
health: async ({ connection: connection2, workflow }, { adminToken, logger: logger2, read, reconcileScopes, resolveSettings, rotateToken, shopify } = {}) => {
|
|
4031
|
-
var _a, _b, _c, _d;
|
|
4107
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4032
4108
|
const request2 = {
|
|
4033
4109
|
connectionId: workflow.connection,
|
|
4034
4110
|
organizationId: workflow.organization,
|
|
@@ -4053,6 +4129,7 @@ var shopify_default2 = {
|
|
|
4053
4129
|
let metered;
|
|
4054
4130
|
let shopCurrency = null;
|
|
4055
4131
|
let billingProbeFailed = false;
|
|
4132
|
+
let reconciliation = null;
|
|
4056
4133
|
try {
|
|
4057
4134
|
if (!(source == null ? void 0 : source.id)) {
|
|
4058
4135
|
const shopData = await shopify.oauth.getShop({ adminAccessToken, shop: connection2.shop });
|
|
@@ -4073,45 +4150,99 @@ var shopify_default2 = {
|
|
|
4073
4150
|
const partnerRow = (read == null ? void 0 : read.get) ? await read.get({ collection: "provider", query: { slug: "shopify" } }) : null;
|
|
4074
4151
|
const partner = (partnerRow == null ? void 0 : partnerRow.settings) ? decrypt(partnerRow.settings) : {};
|
|
4075
4152
|
if (partner.partnerToken && partner.partnerOrgId && partner.partnerAppId && (source == null ? void 0 : source.id) && ((_b = shopify.partner) == null ? void 0 : _b.getUsageChargeEvents)) {
|
|
4153
|
+
const ledgerFloor = new Date(Date.now() - 30 * 24 * 60 * 60 * 1e3);
|
|
4076
4154
|
const accruals = await shopify.partner.getUsageChargeEvents({
|
|
4077
4155
|
appId: "gid://shopify/App/" + partner.partnerAppId,
|
|
4078
|
-
first:
|
|
4079
|
-
occurredAtMin:
|
|
4156
|
+
first: 10,
|
|
4157
|
+
occurredAtMin: ledgerFloor.toISOString(),
|
|
4080
4158
|
organizationId: partner.partnerOrgId,
|
|
4081
4159
|
partnerToken: partner.partnerToken,
|
|
4082
4160
|
shopId: "gid://shopify/Shop/" + source.id
|
|
4083
4161
|
});
|
|
4084
|
-
const
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4162
|
+
const boundaries = accruals.filter((event) => event.occurredAt).sort((a, b) => new Date(a.occurredAt) - new Date(b.occurredAt));
|
|
4163
|
+
const accrued = [...boundaries].reverse().find((event) => Number(event.usageQuantity) > 0);
|
|
4164
|
+
if (accrued) metered = String(accrued.chargeId || accrued.id);
|
|
4165
|
+
const stampedAt = (_c = boundaries.find(
|
|
4166
|
+
(event) => {
|
|
4167
|
+
var _a2;
|
|
4168
|
+
return String(event.chargeId || event.id) === String(((_a2 = connection2.source) == null ? void 0 : _a2.metered) || "");
|
|
4169
|
+
}
|
|
4170
|
+
)) == null ? void 0 : _c.occurredAt;
|
|
4171
|
+
reconciliation = [];
|
|
4172
|
+
let windowStart = ledgerFloor;
|
|
4173
|
+
for (const boundary of boundaries) {
|
|
4174
|
+
const windowEnd = new Date(boundary.occurredAt);
|
|
4175
|
+
const windowOpensAt = windowStart;
|
|
4176
|
+
windowStart = windowEnd;
|
|
4177
|
+
if (stampedAt && windowEnd <= new Date(stampedAt)) continue;
|
|
4178
|
+
const charged = Math.round(Number(boundary.usageQuantity) || 0);
|
|
4179
|
+
const [tally] = await read.aggregate({
|
|
4088
4180
|
collection: "order",
|
|
4089
|
-
|
|
4090
|
-
$
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4181
|
+
pipeline: [
|
|
4182
|
+
{ $match: {
|
|
4183
|
+
"billed.date": { $gt: windowOpensAt, $lte: windowEnd },
|
|
4184
|
+
"billed.void": { $in: [null] },
|
|
4185
|
+
organization: workflow.organization,
|
|
4186
|
+
"provider.slug": "shopify"
|
|
4187
|
+
} },
|
|
4188
|
+
{ $group: {
|
|
4189
|
+
_id: null,
|
|
4190
|
+
billed: { $sum: "$billed.amount" },
|
|
4191
|
+
orders: { $push: "$id" }
|
|
4192
|
+
} }
|
|
4193
|
+
]
|
|
4194
|
+
}) || [];
|
|
4195
|
+
const billed = (tally == null ? void 0 : tally.billed) || 0;
|
|
4196
|
+
const orders = (tally == null ? void 0 : tally.orders) || [];
|
|
4197
|
+
const charge = String(boundary.chargeId || boundary.id);
|
|
4198
|
+
const balanced = charged === billed;
|
|
4199
|
+
if (!(charged || billed)) continue;
|
|
4200
|
+
if (balanced) {
|
|
4201
|
+
writes.push({
|
|
4202
|
+
collection: "order",
|
|
4203
|
+
data: {
|
|
4204
|
+
$set: { "billed.receipt": charge }
|
|
4205
|
+
},
|
|
4206
|
+
// Top-level, not an option — the controller takes
|
|
4207
|
+
// `multiple` beside `options`, and the shell
|
|
4208
|
+
// forwards it as such.
|
|
4209
|
+
multiple: true,
|
|
4210
|
+
operation: "update",
|
|
4211
|
+
query: {
|
|
4212
|
+
"billed.date": { $gt: windowOpensAt, $lte: windowEnd },
|
|
4213
|
+
"billed.receipt": { $in: [null] },
|
|
4214
|
+
"billed.void": { $in: [null] },
|
|
4215
|
+
organization: workflow.organization,
|
|
4216
|
+
"provider.slug": "shopify"
|
|
4217
|
+
}
|
|
4218
|
+
});
|
|
4219
|
+
} else {
|
|
4220
|
+
(_d = logger2 == null ? void 0 : logger2.error) == null ? void 0 : _d.call(logger2, new Error(
|
|
4221
|
+
"shopify.usage.reconciliation.mismatch on shop " + connection2.shop + ": charge " + charge + " charged " + charged + " cents but its window holds " + billed + " cents across " + orders.length + " billed orders \u2014 each cent of difference is commission that never charged"
|
|
4222
|
+
), {
|
|
4223
|
+
extra: {
|
|
4224
|
+
billed,
|
|
4225
|
+
charge,
|
|
4226
|
+
charged,
|
|
4227
|
+
orders: orders.slice(0, 50),
|
|
4228
|
+
shop: connection2.shop,
|
|
4229
|
+
windowEnd,
|
|
4230
|
+
windowStart: windowOpensAt
|
|
4231
|
+
}
|
|
4232
|
+
});
|
|
4233
|
+
}
|
|
4234
|
+
reconciliation.push({ balanced, billed, charge, charged, occurredAt: boundary.occurredAt, orders: orders.length });
|
|
4104
4235
|
}
|
|
4105
4236
|
}
|
|
4106
4237
|
} catch (probeError) {
|
|
4107
4238
|
billingProbeFailed = true;
|
|
4108
|
-
(
|
|
4239
|
+
(_e = logger2 == null ? void 0 : logger2.warn) == null ? void 0 : _e.call(logger2, "shopify.health.billing.probe.failed", {
|
|
4109
4240
|
connectionId: connection2.id,
|
|
4110
4241
|
message: probeError == null ? void 0 : probeError.message,
|
|
4111
4242
|
shop: connection2.shop
|
|
4112
4243
|
});
|
|
4113
4244
|
}
|
|
4114
|
-
if (sourceRepaired || metered !== void 0 && metered !== (((
|
|
4245
|
+
if (sourceRepaired || metered !== void 0 && metered !== (((_f = connection2.source) == null ? void 0 : _f.metered) ?? void 0)) {
|
|
4115
4246
|
writes.push({
|
|
4116
4247
|
collection: "connection",
|
|
4117
4248
|
data: {
|
|
@@ -4182,6 +4313,9 @@ var shopify_default2 = {
|
|
|
4182
4313
|
metered: metered ?? null,
|
|
4183
4314
|
meterProbed: metered !== void 0,
|
|
4184
4315
|
pingedAt: /* @__PURE__ */ new Date(),
|
|
4316
|
+
// One entry per boundary charge judged this run: what
|
|
4317
|
+
// Shopify charged vs what the window's orders billed.
|
|
4318
|
+
...reconciliation && { reconciliation },
|
|
4185
4319
|
refreshTokenExpiresAt: refreshTokenExpiresAt || null,
|
|
4186
4320
|
refreshTokenRotated,
|
|
4187
4321
|
scopesMissing,
|
|
@@ -4321,28 +4455,34 @@ var shopify_default2 = {
|
|
|
4321
4455
|
// name required by the manifest and enterable nowhere is a vendor that can
|
|
4322
4456
|
// never go live from the admin screen.
|
|
4323
4457
|
provider: {
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4458
|
+
vendors: {
|
|
4459
|
+
shopify: {
|
|
4460
|
+
fields: [
|
|
4461
|
+
{ input: "text", key: "apiKey", credential: "SHOPIFY_API_KEY", label: "API key", message: "The app's Client ID \u2014 Dev Dashboard, the app, Settings.", required: true },
|
|
4462
|
+
{ input: "password", key: "apiSecret", credential: "SHOPIFY_API_SECRET", label: "API secret", message: "The app's Client secret, beside the Client ID in the app's settings.", redact: true, required: true },
|
|
4463
|
+
{ input: "text", key: "appHandle", credential: "SHOPIFY_APP_HANDLE", label: "App handle", message: "The app's URL handle (for example drawbridge-development), from the app's configuration.", required: true },
|
|
4464
|
+
{ input: "text", key: "listingUrl", credential: "SHOPIFY_APP_LISTING_URL", label: "App listing URL", message: 'Where "View on the Shopify App Store" sends merchants \u2014 the public listing, or the Dev Dashboard install link for the dev app.', required: true },
|
|
4465
|
+
// The usage meter's event handle, when the plan config's meter ever
|
|
4466
|
+
// changes: stored value overrides the built-in default
|
|
4467
|
+
// (events.order.handle) at the mint point, and `format : 'slug'`
|
|
4468
|
+
// normalizes it on save — a handle can carry no spaces or capitals,
|
|
4469
|
+
// and classification against it is case-sensitive. Optional: empty
|
|
4470
|
+
// means the default, and the sender still refuses any handle that
|
|
4471
|
+
// disagrees with the transaction it minted.
|
|
4472
|
+
{ format: "slug", input: "text", key: "orderEventHandle", label: "Order event handle", message: "Must match the usage meter's Handle field on the plan exactly \u2014 lowercase and hyphens. Leave empty to use drawbridge-orders.", required: false, setting: true },
|
|
4473
|
+
// The Partner API credential set — the ONE place meter billing is
|
|
4474
|
+
// observable (CHARGE_USAGE accrual events). Org id and numeric app
|
|
4475
|
+
// id come from the Partner Dashboard; the token from Settings →
|
|
4476
|
+
// Partner API clients (Manage-apps permission). All optional: the
|
|
4477
|
+
// accrual probe simply stays off until they exist.
|
|
4478
|
+
{ input: "text", key: "partnerOrgId", label: "Partner organization ID", message: "The number in the Partner Dashboard URL \u2014 partners.shopify.com/<this number>/\u2026 \u2014 NOT the admin organization_id from the app listing link.", required: false, setting: true },
|
|
4479
|
+
{ input: "text", key: "partnerAppId", label: "Partner app ID (numeric)", message: "The numeric id in the app's Partner Dashboard URL \u2014 not the Client ID.", required: false, setting: true },
|
|
4480
|
+
{ input: "password", key: "partnerToken", label: "Partner API token", message: "Partner Dashboard, Settings, Partner API clients \u2014 create one with Manage apps and paste the prtapi_ token.", redact: true, required: false, setting: true }
|
|
4481
|
+
],
|
|
4482
|
+
icon: shopify_default,
|
|
4483
|
+
name: "Shopify"
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4346
4486
|
},
|
|
4347
4487
|
// A pre-launch integration: it only surfaces once the App Store listing
|
|
4348
4488
|
// exists and the app is fully configured. Requiring all four means it can
|
|
@@ -4823,8 +4963,19 @@ var implemented = (hooks, path) => {
|
|
|
4823
4963
|
var leaves = (node, path = []) => Object.entries(node || {}).flatMap(
|
|
4824
4964
|
([key, value]) => typeof value === "function" ? [[[...path, key].join("."), value]] : value && typeof value === "object" ? leaves(value, [...path, key]) : []
|
|
4825
4965
|
);
|
|
4966
|
+
var checkIcon = (owner, icon) => {
|
|
4967
|
+
if (typeof icon !== "string" || !icon.includes("<svg")) {
|
|
4968
|
+
throw new Error(owner + " needs an icon \u2014 the svg markup itself, not a path to one");
|
|
4969
|
+
}
|
|
4970
|
+
if (!icon.includes("viewBox")) {
|
|
4971
|
+
throw new Error(owner + " icon has no viewBox, so it cannot scale");
|
|
4972
|
+
}
|
|
4973
|
+
if (icon.includes("<image")) {
|
|
4974
|
+
throw new Error(owner + " icon wraps a raster \u2014 re-export it as vector shapes");
|
|
4975
|
+
}
|
|
4976
|
+
};
|
|
4826
4977
|
var build = (manifest) => {
|
|
4827
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
4978
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
4828
4979
|
if (!(manifest == null ? void 0 : manifest.slug)) throw new Error("A connection needs a slug");
|
|
4829
4980
|
if (!(manifest == null ? void 0 : manifest.title)) throw new Error(manifest.slug + " needs a title");
|
|
4830
4981
|
if (!(manifest == null ? void 0 : manifest.private) && !(manifest == null ? void 0 : manifest.feature)) throw new Error(manifest.slug + " needs a plan feature key");
|
|
@@ -4854,46 +5005,53 @@ var build = (manifest) => {
|
|
|
4854
5005
|
}
|
|
4855
5006
|
}
|
|
4856
5007
|
}
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
5008
|
+
if ((_c = manifest.provider) == null ? void 0 : _c.fields) {
|
|
5009
|
+
throw new Error(manifest.slug + " declares provider.fields \u2014 fields live under provider.vendors.<vendor> now, keyed by the vendor that holds them");
|
|
5010
|
+
}
|
|
5011
|
+
const declaredKeys = /* @__PURE__ */ new Set();
|
|
5012
|
+
for (const [vendor, declared] of Object.entries(((_d = manifest.provider) == null ? void 0 : _d.vendors) || {})) {
|
|
5013
|
+
if (!(declared == null ? void 0 : declared.name)) throw new Error(manifest.slug + " declares vendor " + vendor + " with no name");
|
|
5014
|
+
checkIcon(manifest.slug + " vendor " + vendor, declared.icon);
|
|
5015
|
+
if (!Array.isArray(declared.fields) || !declared.fields.length) {
|
|
5016
|
+
throw new Error(manifest.slug + " declares vendor " + vendor + " with no fields \u2014 a vendor nothing is typed into holds nothing");
|
|
4863
5017
|
}
|
|
4864
|
-
|
|
4865
|
-
|
|
5018
|
+
for (const field2 of declared.fields) {
|
|
5019
|
+
if (!(field2 == null ? void 0 : field2.key) || !(field2 == null ? void 0 : field2.label)) {
|
|
5020
|
+
throw new Error(manifest.slug + " declares a provider field with no key or label");
|
|
5021
|
+
}
|
|
5022
|
+
if (!INPUTS.includes(field2.input)) {
|
|
5023
|
+
throw new Error(manifest.slug + ".provider." + field2.key + " needs an input the admin form can render \u2014 one of " + INPUTS.join(", "));
|
|
5024
|
+
}
|
|
5025
|
+
if (field2.input === "password" && !field2.redact) {
|
|
5026
|
+
throw new Error(manifest.slug + ".provider." + field2.key + " is a password and must declare redact : true \u2014 the api would hand the value back");
|
|
5027
|
+
}
|
|
5028
|
+
if (declaredKeys.has(field2.key)) {
|
|
5029
|
+
throw new Error(manifest.slug + " declares " + field2.key + " under two vendors \u2014 vendorSettings() merges them and one would win");
|
|
5030
|
+
}
|
|
5031
|
+
declaredKeys.add(field2.key);
|
|
4866
5032
|
}
|
|
4867
5033
|
}
|
|
4868
|
-
|
|
4869
|
-
throw new Error(manifest.slug + " needs an icon \u2014 the svg markup itself, not a path to one");
|
|
4870
|
-
}
|
|
4871
|
-
if (!manifest.icon.includes("viewBox")) {
|
|
4872
|
-
throw new Error(manifest.slug + " icon has no viewBox, so it cannot scale");
|
|
4873
|
-
}
|
|
4874
|
-
if (manifest.icon.includes("<image")) {
|
|
4875
|
-
throw new Error(manifest.slug + " icon wraps a raster \u2014 re-export it as vector shapes");
|
|
4876
|
-
}
|
|
5034
|
+
checkIcon(manifest.slug, manifest == null ? void 0 : manifest.icon);
|
|
4877
5035
|
if (!GROUPS.includes(manifest == null ? void 0 : manifest.group)) {
|
|
4878
5036
|
throw new Error(manifest.slug + " needs a group \u2014 one of " + GROUPS.join(", "));
|
|
4879
5037
|
}
|
|
4880
|
-
if ((
|
|
5038
|
+
if ((_e = manifest == null ? void 0 : manifest.connect) == null ? void 0 : _e.type) {
|
|
4881
5039
|
throw new Error(manifest.slug + " declares connect.type \u2014 that is auth.type now");
|
|
4882
5040
|
}
|
|
4883
|
-
if (!AUTH_TYPES.includes((
|
|
5041
|
+
if (!AUTH_TYPES.includes((_f = manifest == null ? void 0 : manifest.auth) == null ? void 0 : _f.type)) {
|
|
4884
5042
|
throw new Error(manifest.slug + " needs auth.type \u2014 one of " + AUTH_TYPES.join(", "));
|
|
4885
5043
|
}
|
|
4886
5044
|
if (manifest.auth.type === "oauth") {
|
|
4887
5045
|
for (const field2 of OAUTH_FIELDS) {
|
|
4888
|
-
if (!((
|
|
5046
|
+
if (!((_g = manifest.auth.oauth) == null ? void 0 : _g[field2])) {
|
|
4889
5047
|
throw new Error(manifest.slug + " is oauth and must declare auth.oauth." + field2);
|
|
4890
5048
|
}
|
|
4891
5049
|
}
|
|
4892
|
-
if (typeof ((
|
|
5050
|
+
if (typeof ((_i = (_h = manifest.hooks) == null ? void 0 : _h.auth) == null ? void 0 : _i.token) !== "function") {
|
|
4893
5051
|
throw new Error(manifest.slug + " is oauth and must implement hooks.auth.token \u2014 point it at authToken() or wrap it");
|
|
4894
5052
|
}
|
|
4895
5053
|
for (const url of OAUTH_URLS) {
|
|
4896
|
-
if (!((
|
|
5054
|
+
if (!((_k = (_j = manifest.auth.oauth) == null ? void 0 : _j.urls) == null ? void 0 : _k[url])) {
|
|
4897
5055
|
throw new Error(manifest.slug + " is oauth and must declare auth.oauth.urls." + url);
|
|
4898
5056
|
}
|
|
4899
5057
|
}
|
|
@@ -4903,16 +5061,16 @@ var build = (manifest) => {
|
|
|
4903
5061
|
);
|
|
4904
5062
|
}
|
|
4905
5063
|
}
|
|
4906
|
-
if (implemented(manifest.hooks, "inbound.event") && typeof ((
|
|
5064
|
+
if (implemented(manifest.hooks, "inbound.event") && typeof ((_m = (_l = manifest.hooks) == null ? void 0 : _l.inbound) == null ? void 0 : _m.event) !== "function" && !((_o = (_n = manifest.inbound) == null ? void 0 : _n.headers) == null ? void 0 : _o.event)) {
|
|
4907
5065
|
throw new Error(manifest.slug + " implements inbound.event but declares no inbound.headers.event");
|
|
4908
5066
|
}
|
|
4909
|
-
if (implemented(manifest.hooks, "inbound.verify") && !((
|
|
5067
|
+
if (implemented(manifest.hooks, "inbound.verify") && !((_q = (_p = manifest.inbound) == null ? void 0 : _p.headers) == null ? void 0 : _q.signature)) {
|
|
4910
5068
|
throw new Error(manifest.slug + " implements inbound.verify but declares no inbound.headers.signature");
|
|
4911
5069
|
}
|
|
4912
5070
|
if (typeof (manifest == null ? void 0 : manifest.status) !== "function") {
|
|
4913
5071
|
throw new Error(manifest.slug + " must declare status( data ) \u2014 return null to accept the connection's own status, or { message, status } to override it");
|
|
4914
5072
|
}
|
|
4915
|
-
if (!Array.isArray((
|
|
5073
|
+
if (!Array.isArray((_r = manifest == null ? void 0 : manifest.content) == null ? void 0 : _r.guide) || !manifest.content.guide.length) {
|
|
4916
5074
|
throw new Error(manifest.slug + " needs content.guide \u2014 an array of steps for its page");
|
|
4917
5075
|
}
|
|
4918
5076
|
if (typeof (manifest == null ? void 0 : manifest.status) !== "function") {
|
|
@@ -4924,8 +5082,8 @@ var build = (manifest) => {
|
|
|
4924
5082
|
}
|
|
4925
5083
|
for (const [domain, verbs] of Object.entries(HOOKS)) {
|
|
4926
5084
|
for (const verb of verbs) {
|
|
4927
|
-
const hook = (
|
|
4928
|
-
if (((
|
|
5085
|
+
const hook = (_t = (_s = manifest.hooks) == null ? void 0 : _s[domain]) == null ? void 0 : _t[verb];
|
|
5086
|
+
if (((_u = manifest.hooks) == null ? void 0 : _u[domain]) === false) continue;
|
|
4929
5087
|
if (hook !== false && !implemented({ [domain]: { [verb]: hook } }, domain + "." + verb)) {
|
|
4930
5088
|
throw new Error(manifest.slug + " must answer hooks." + domain + "." + verb + " \u2014 false, a function, or {} if another repo implements it");
|
|
4931
5089
|
}
|
|
@@ -4970,6 +5128,44 @@ var connections = Object.freeze({
|
|
|
4970
5128
|
shopify: build(shopify_default2),
|
|
4971
5129
|
webhook: build(webhook_default)
|
|
4972
5130
|
});
|
|
5131
|
+
var canonical = (field2) => JSON.stringify(Object.fromEntries(Object.entries(field2).sort()));
|
|
5132
|
+
var mergeVendors = (catalog) => {
|
|
5133
|
+
var _a;
|
|
5134
|
+
const merged = {};
|
|
5135
|
+
const claimed = /* @__PURE__ */ new Map();
|
|
5136
|
+
for (const [slug2, manifest] of Object.entries(catalog)) {
|
|
5137
|
+
for (const [vendor, declared] of Object.entries(((_a = manifest.provider) == null ? void 0 : _a.vendors) || {})) {
|
|
5138
|
+
const held = merged[vendor] || (merged[vendor] = { fields: [], icon: declared.icon, name: declared.name });
|
|
5139
|
+
if (held.name !== declared.name) {
|
|
5140
|
+
throw new Error(slug2 + " names vendor " + vendor + ' "' + declared.name + '" but another manifest names it "' + held.name + '"');
|
|
5141
|
+
}
|
|
5142
|
+
if (held.icon !== declared.icon) {
|
|
5143
|
+
throw new Error(slug2 + " declares a different icon for vendor " + vendor + " than another manifest \u2014 one vendor, one mark");
|
|
5144
|
+
}
|
|
5145
|
+
for (const field2 of declared.fields) {
|
|
5146
|
+
const existing = held.fields.find((entry) => entry.key === field2.key);
|
|
5147
|
+
if (existing) {
|
|
5148
|
+
if (canonical(existing) !== canonical(field2)) {
|
|
5149
|
+
throw new Error(slug2 + " declares " + vendor + "." + field2.key + " differently from another manifest \u2014 a field two connections spend is declared identically in both");
|
|
5150
|
+
}
|
|
5151
|
+
continue;
|
|
5152
|
+
}
|
|
5153
|
+
if (field2.credential) {
|
|
5154
|
+
const owner = claimed.get(field2.credential);
|
|
5155
|
+
if (owner) {
|
|
5156
|
+
throw new Error(field2.credential + " is claimed by both " + owner + " and " + vendor + "." + field2.key + " \u2014 one would silently overwrite the other");
|
|
5157
|
+
}
|
|
5158
|
+
claimed.set(field2.credential, vendor + "." + field2.key);
|
|
5159
|
+
}
|
|
5160
|
+
held.fields.push(field2);
|
|
5161
|
+
}
|
|
5162
|
+
}
|
|
5163
|
+
}
|
|
5164
|
+
return Object.freeze(Object.fromEntries(
|
|
5165
|
+
Object.entries(merged).map(([vendor, held]) => [vendor, Object.freeze({ ...held, fields: Object.freeze(held.fields) })])
|
|
5166
|
+
));
|
|
5167
|
+
};
|
|
5168
|
+
var vendors = mergeVendors(connections);
|
|
4973
5169
|
(() => {
|
|
4974
5170
|
var _a;
|
|
4975
5171
|
const routes = {};
|
|
@@ -5042,11 +5238,8 @@ var publicConnectionKeys = Object.freeze([
|
|
|
5042
5238
|
]);
|
|
5043
5239
|
|
|
5044
5240
|
// lib/providers.js
|
|
5045
|
-
var providerFields = (slug2) =>
|
|
5046
|
-
|
|
5047
|
-
return Object.hasOwn(connections, slug2) ? ((_a = connections[slug2].provider) == null ? void 0 : _a.fields) || [] : [];
|
|
5048
|
-
};
|
|
5049
|
-
var providerSlugs = () => Object.keys(connections).filter((slug2) => connections[slug2].provider).sort();
|
|
5241
|
+
var providerFields = (slug2) => Object.hasOwn(vendors, slug2) ? vendors[slug2].fields : [];
|
|
5242
|
+
var providerSlugs = () => Object.keys(vendors).sort();
|
|
5050
5243
|
var isLive = (slug2, settings) => {
|
|
5051
5244
|
const fields2 = providerFields(slug2);
|
|
5052
5245
|
if (!fields2.length) return false;
|
|
@@ -5071,6 +5264,15 @@ var providerSettings = async ({ controller, slug: slug2 }) => {
|
|
|
5071
5264
|
providerMemo.set(slug2, { at: Date.now(), value });
|
|
5072
5265
|
return value;
|
|
5073
5266
|
};
|
|
5267
|
+
var vendorSettings = async ({ controller, slug: slug2 }) => {
|
|
5268
|
+
var _a;
|
|
5269
|
+
const declared = Object.hasOwn(connections, slug2) ? Object.keys(((_a = connections[slug2].provider) == null ? void 0 : _a.vendors) || {}) : [];
|
|
5270
|
+
let merged = {};
|
|
5271
|
+
for (const vendor of declared) {
|
|
5272
|
+
merged = { ...merged, ...await providerSettings({ controller, slug: vendor }) };
|
|
5273
|
+
}
|
|
5274
|
+
return merged;
|
|
5275
|
+
};
|
|
5074
5276
|
var saveProviderSettings = async ({ authenticated, clear, controller, settings, slug: slug2 }) => {
|
|
5075
5277
|
const fields2 = providerFields(slug2);
|
|
5076
5278
|
if (!fields2.length) return null;
|
|
@@ -5132,5 +5334,7 @@ export {
|
|
|
5132
5334
|
providerMemo,
|
|
5133
5335
|
providerSettings,
|
|
5134
5336
|
providerSlugs,
|
|
5135
|
-
saveProviderSettings
|
|
5337
|
+
saveProviderSettings,
|
|
5338
|
+
vendorSettings,
|
|
5339
|
+
vendors
|
|
5136
5340
|
};
|