vairified 0.3.2 → 0.6.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.
- package/README.md +104 -3
- package/dist/index.cjs +419 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +401 -6
- package/dist/index.d.ts +401 -6
- package/dist/index.js +417 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -254,6 +254,19 @@ var TournamentImportResult = class {
|
|
|
254
254
|
dryRun;
|
|
255
255
|
message;
|
|
256
256
|
errors;
|
|
257
|
+
/**
|
|
258
|
+
* Public member ids for the ghost players THIS import created, keyed by the
|
|
259
|
+
* `ref` supplied in `ghostMembers[]`.
|
|
260
|
+
*
|
|
261
|
+
* Empty on a dry-run, and empty for entries the import matched to a player who
|
|
262
|
+
* already existed — resolving an existing email to a member requires the
|
|
263
|
+
* `key:player:lookup` scope and `members.getByEmail()`.
|
|
264
|
+
*
|
|
265
|
+
* Use these ids directly in a follow-up `matches.submit()`; without them an
|
|
266
|
+
* import reports only how many accounts it caused and you cannot address any
|
|
267
|
+
* of them.
|
|
268
|
+
*/
|
|
269
|
+
createdGhostMembers;
|
|
257
270
|
/** @internal */
|
|
258
271
|
constructor(wire) {
|
|
259
272
|
this.success = wire.success;
|
|
@@ -264,6 +277,11 @@ var TournamentImportResult = class {
|
|
|
264
277
|
this.dryRun = wire.dryRun ?? false;
|
|
265
278
|
this.message = wire.message;
|
|
266
279
|
this.errors = Object.freeze(wire.errors ?? []);
|
|
280
|
+
this.createdGhostMembers = Object.freeze(
|
|
281
|
+
(wire.createdGhostMembers ?? []).map(
|
|
282
|
+
(entry) => Object.freeze({ ref: entry.ref, memberId: entry.memberId })
|
|
283
|
+
)
|
|
284
|
+
);
|
|
267
285
|
Object.freeze(this);
|
|
268
286
|
}
|
|
269
287
|
/** True when the import succeeded without errors. */
|
|
@@ -366,10 +384,22 @@ var SportRating = class {
|
|
|
366
384
|
rating;
|
|
367
385
|
/** Category abbreviation for the primary rating (e.g. `'VO'`). */
|
|
368
386
|
abbr;
|
|
387
|
+
/** Player is VAIRified in this sport (has a verified, non-recreational rating). */
|
|
388
|
+
isVairified;
|
|
389
|
+
/** Player is an active VAIR Pro (can rate) in this sport. Alias of {@link isVairPro}. */
|
|
390
|
+
isRater;
|
|
391
|
+
/** Player is an active VAIR Pro (can rate) in this sport. */
|
|
392
|
+
isVairPro;
|
|
393
|
+
/** VAIR-Pro lifecycle status in this sport (`'ACTIVE'` / `'PENDING'` / `null`). */
|
|
394
|
+
isVairProStatus;
|
|
369
395
|
#splits;
|
|
370
396
|
constructor(wire) {
|
|
371
397
|
this.rating = wire.rating;
|
|
372
398
|
this.abbr = wire.abbr;
|
|
399
|
+
this.isVairified = wire.isVairified ?? false;
|
|
400
|
+
this.isRater = wire.isRater ?? false;
|
|
401
|
+
this.isVairPro = wire.isVairPro ?? false;
|
|
402
|
+
this.isVairProStatus = wire.isVairProStatus ?? null;
|
|
373
403
|
this.#splits = new Map(Object.entries(wire.ratingSplits ?? {}));
|
|
374
404
|
Object.freeze(this);
|
|
375
405
|
}
|
|
@@ -454,6 +484,20 @@ var Member = class {
|
|
|
454
484
|
state;
|
|
455
485
|
zip;
|
|
456
486
|
country;
|
|
487
|
+
/**
|
|
488
|
+
* The DATE this member's VAIR account was created (`YYYY-MM-DD`, UTC), or
|
|
489
|
+
* `null` when the endpoint does not supply it.
|
|
490
|
+
*
|
|
491
|
+
* Present on `members.get()`, `members.getBulk()` and `members.getByEmail()` —
|
|
492
|
+
* the calls where you already know which member you asked about. **Never on
|
|
493
|
+
* `members.search()`**, which is discovery: account age is not something you
|
|
494
|
+
* can browse strangers by.
|
|
495
|
+
*
|
|
496
|
+
* Deliberately a date, not a timestamp. It exists so you can apply a
|
|
497
|
+
* new-accounts-only referral rule — crediting an ambassador only for accounts
|
|
498
|
+
* created because of their event.
|
|
499
|
+
*/
|
|
500
|
+
memberSince;
|
|
457
501
|
gender;
|
|
458
502
|
status;
|
|
459
503
|
sport;
|
|
@@ -472,6 +516,7 @@ var Member = class {
|
|
|
472
516
|
this.state = wire.state ?? null;
|
|
473
517
|
this.zip = wire.zip ?? null;
|
|
474
518
|
this.country = wire.country ?? null;
|
|
519
|
+
this.memberSince = wire.memberSince ?? null;
|
|
475
520
|
this.gender = wire.gender ?? null;
|
|
476
521
|
this.status = Object.freeze({ ...wire.status });
|
|
477
522
|
this.sport = new MemberSportMap(wire.sport);
|
|
@@ -519,6 +564,70 @@ var Member = class {
|
|
|
519
564
|
}
|
|
520
565
|
};
|
|
521
566
|
|
|
567
|
+
// src/models/members-by-email-result.ts
|
|
568
|
+
var MemberEmailMatch = class {
|
|
569
|
+
/** The address exactly as you supplied it, not as stored. */
|
|
570
|
+
email;
|
|
571
|
+
/** Every member holding this address. Never empty. */
|
|
572
|
+
members;
|
|
573
|
+
/** @internal */
|
|
574
|
+
constructor(wire) {
|
|
575
|
+
this.email = wire.email;
|
|
576
|
+
this.members = Object.freeze(wire.members.map((m) => new Member(m)));
|
|
577
|
+
Object.freeze(this);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* The single member for this address, or `null` when the address is
|
|
581
|
+
* ambiguous (more than one match).
|
|
582
|
+
*
|
|
583
|
+
* Use this rather than `members[0]` when a wrong link is worse than no
|
|
584
|
+
* link — it refuses to guess instead of silently picking one.
|
|
585
|
+
*/
|
|
586
|
+
get sole() {
|
|
587
|
+
return this.members.length === 1 ? this.members[0] ?? null : null;
|
|
588
|
+
}
|
|
589
|
+
/** Whether this address resolved to more than one member. */
|
|
590
|
+
get isAmbiguous() {
|
|
591
|
+
return this.members.length > 1;
|
|
592
|
+
}
|
|
593
|
+
toString() {
|
|
594
|
+
return `MemberEmailMatch ${this.email} -> ${this.members.length} member(s)`;
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var MembersByEmailResult = class {
|
|
598
|
+
matched;
|
|
599
|
+
/** Addresses that resolved to nothing, echoed as you supplied them. */
|
|
600
|
+
notFound;
|
|
601
|
+
/** @internal */
|
|
602
|
+
constructor(wire) {
|
|
603
|
+
this.matched = Object.freeze(wire.matched.map((m) => new MemberEmailMatch(m)));
|
|
604
|
+
this.notFound = Object.freeze([...wire.notFound]);
|
|
605
|
+
Object.freeze(this);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Look up one address's match, case-insensitively.
|
|
609
|
+
*
|
|
610
|
+
* Saves callers a linear scan and, more importantly, saves them from
|
|
611
|
+
* matching case-sensitively against an address the server echoed back
|
|
612
|
+
* in whatever case they originally sent.
|
|
613
|
+
*/
|
|
614
|
+
get(email) {
|
|
615
|
+
const needle = email.trim().toLowerCase();
|
|
616
|
+
return this.matched.find((m) => m.email.toLowerCase() === needle) ?? null;
|
|
617
|
+
}
|
|
618
|
+
/** Whether every requested address resolved to at least one member. */
|
|
619
|
+
get allResolved() {
|
|
620
|
+
return this.notFound.length === 0;
|
|
621
|
+
}
|
|
622
|
+
/** Total number of members across every matched address. */
|
|
623
|
+
get memberCount() {
|
|
624
|
+
return this.matched.reduce((n, m) => n + m.members.length, 0);
|
|
625
|
+
}
|
|
626
|
+
toString() {
|
|
627
|
+
return `MembersByEmailResult matched=${this.matched.length} notFound=${this.notFound.length}`;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
|
|
522
631
|
// src/models/rating-update.ts
|
|
523
632
|
var RatingUpdate = class {
|
|
524
633
|
memberId;
|
|
@@ -567,6 +676,7 @@ var RatingUpdate = class {
|
|
|
567
676
|
// src/resources/members.ts
|
|
568
677
|
var DEFAULT_PAGE_SIZE = 20;
|
|
569
678
|
var MAX_PAGE_SIZE = 100;
|
|
679
|
+
var MAX_EMAILS_PER_LOOKUP = 100;
|
|
570
680
|
var MembersResource = class {
|
|
571
681
|
#http;
|
|
572
682
|
/** @internal */
|
|
@@ -708,6 +818,70 @@ var MembersResource = class {
|
|
|
708
818
|
});
|
|
709
819
|
return rows.map((row) => new Member(row));
|
|
710
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Resolve up to 100 members by their **exact** email address.
|
|
823
|
+
*
|
|
824
|
+
* Use this to link your users to their VAIR identity when you hold
|
|
825
|
+
* their email but not their member ID — e.g. resolving a tournament
|
|
826
|
+
* roster at registration instead of waiting for each player to
|
|
827
|
+
* complete SSO.
|
|
828
|
+
*
|
|
829
|
+
* **Requires the `key:player:lookup` scope**, which is granted per
|
|
830
|
+
* partner on approval. Holding `key:player:search` does not imply it.
|
|
831
|
+
*
|
|
832
|
+
* Matching is exact and case-insensitive; there is deliberately no
|
|
833
|
+
* partial, prefix or fuzzy matching. Every address you supply comes
|
|
834
|
+
* back in either `matched` or `notFound`, so read `notFound` directly
|
|
835
|
+
* instead of diffing your input against the results.
|
|
836
|
+
*
|
|
837
|
+
* A `notFound` address is **not** proof the person has no VAIR
|
|
838
|
+
* account — unclaimed imported records are excluded from this lookup.
|
|
839
|
+
*
|
|
840
|
+
* @param emails - Email addresses to resolve (max 100).
|
|
841
|
+
* @param options - Optional filters.
|
|
842
|
+
* @param options.sport - Sport code to scope ratings (e.g. `'pickleball'`).
|
|
843
|
+
* @throws {@link ValidationError} If more than 100 addresses are
|
|
844
|
+
* provided, or the list is empty.
|
|
845
|
+
* @category Members
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* ```ts
|
|
849
|
+
* const result = await client.members.getByEmail([
|
|
850
|
+
* 'ada@example.com',
|
|
851
|
+
* 'nobody@example.com',
|
|
852
|
+
* ]);
|
|
853
|
+
*
|
|
854
|
+
* for (const match of result.matched) {
|
|
855
|
+
* const member = match.sole; // null when the address is ambiguous
|
|
856
|
+
* if (member) console.log(match.email, '->', member.memberId);
|
|
857
|
+
* }
|
|
858
|
+
*
|
|
859
|
+
* console.log('no VAIR account found for:', result.notFound);
|
|
860
|
+
* ```
|
|
861
|
+
*/
|
|
862
|
+
async getByEmail(emails, options) {
|
|
863
|
+
if (emails.length === 0) {
|
|
864
|
+
throw new ValidationError("At least one email address is required");
|
|
865
|
+
}
|
|
866
|
+
if (emails.length > MAX_EMAILS_PER_LOOKUP) {
|
|
867
|
+
throw new ValidationError(`Maximum ${MAX_EMAILS_PER_LOOKUP} email addresses per request`);
|
|
868
|
+
}
|
|
869
|
+
const offender = emails.find((e) => e.includes(","));
|
|
870
|
+
if (offender !== void 0) {
|
|
871
|
+
throw new ValidationError(`Email address must not contain a comma: ${offender}`);
|
|
872
|
+
}
|
|
873
|
+
const query = { emails: emails.join(",") };
|
|
874
|
+
if (options?.sport) query.sport = options.sport;
|
|
875
|
+
const wire = await this.#http.request({
|
|
876
|
+
method: "GET",
|
|
877
|
+
path: "/partner/members/by-email",
|
|
878
|
+
query
|
|
879
|
+
});
|
|
880
|
+
return new MembersByEmailResult({
|
|
881
|
+
matched: wire?.matched ?? [],
|
|
882
|
+
notFound: wire?.notFound ?? []
|
|
883
|
+
});
|
|
884
|
+
}
|
|
711
885
|
/**
|
|
712
886
|
* Poll for rating change notifications.
|
|
713
887
|
*
|
|
@@ -820,13 +994,31 @@ function describeScopes(scopes) {
|
|
|
820
994
|
}));
|
|
821
995
|
}
|
|
822
996
|
function generateState() {
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
997
|
+
const webCrypto = globalThis.crypto;
|
|
998
|
+
if (typeof webCrypto?.getRandomValues !== "function") {
|
|
999
|
+
throw new Error(
|
|
1000
|
+
"generateState() needs Web Crypto (crypto.getRandomValues), which is unavailable in this runtime. Node 19+ and browsers have it built in; on React Native / Hermes, install 'react-native-get-random-values' and import it once at your app entry before using the SDK \u2014 or pass your own high-entropy `state` string to oauth.authorize()."
|
|
1001
|
+
);
|
|
828
1002
|
}
|
|
829
|
-
|
|
1003
|
+
const bytes = new Uint8Array(32);
|
|
1004
|
+
webCrypto.getRandomValues(bytes);
|
|
1005
|
+
return base64UrlNoPad(bytes);
|
|
1006
|
+
}
|
|
1007
|
+
var B64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
1008
|
+
function base64UrlNoPad(bytes) {
|
|
1009
|
+
let out = "";
|
|
1010
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
1011
|
+
const b0 = bytes[i] ?? 0;
|
|
1012
|
+
const b1 = bytes[i + 1] ?? 0;
|
|
1013
|
+
const b2 = bytes[i + 2] ?? 0;
|
|
1014
|
+
const hasB1 = i + 1 < bytes.length;
|
|
1015
|
+
const hasB2 = i + 2 < bytes.length;
|
|
1016
|
+
out += B64URL_ALPHABET[b0 >> 2] ?? "";
|
|
1017
|
+
out += B64URL_ALPHABET[(b0 & 3) << 4 | b1 >> 4] ?? "";
|
|
1018
|
+
if (hasB1) out += B64URL_ALPHABET[(b1 & 15) << 2 | b2 >> 6] ?? "";
|
|
1019
|
+
if (hasB2) out += B64URL_ALPHABET[b2 & 63] ?? "";
|
|
1020
|
+
}
|
|
1021
|
+
return out;
|
|
830
1022
|
}
|
|
831
1023
|
function ensureProfileRead(scopes) {
|
|
832
1024
|
if (scopes.includes("user:profile:read")) {
|
|
@@ -928,6 +1120,207 @@ function tokenResponseFromWire(data) {
|
|
|
928
1120
|
};
|
|
929
1121
|
}
|
|
930
1122
|
|
|
1123
|
+
// src/models/attribution.ts
|
|
1124
|
+
var MemberAttribution = class {
|
|
1125
|
+
memberId;
|
|
1126
|
+
/** True when some ambassador already holds credit for this member. */
|
|
1127
|
+
attributed;
|
|
1128
|
+
/**
|
|
1129
|
+
* The member id of the ambassador holding the credit.
|
|
1130
|
+
*
|
|
1131
|
+
* Compare it against your own event host's member id to tell "already credited
|
|
1132
|
+
* to my host — nothing to do" from "credited to somebody else — a person needs
|
|
1133
|
+
* to look, because claiming it takes credit from them".
|
|
1134
|
+
*
|
|
1135
|
+
* `null` both when nobody holds credit and when credit is held by a record that
|
|
1136
|
+
* has no member id of its own, so check {@link attributed} to tell those apart.
|
|
1137
|
+
*/
|
|
1138
|
+
ambassadorMemberId;
|
|
1139
|
+
/** The date the credit was established (`YYYY-MM-DD`), or `null`. */
|
|
1140
|
+
attributedAt;
|
|
1141
|
+
/** @internal */
|
|
1142
|
+
constructor(wire) {
|
|
1143
|
+
this.memberId = wire.memberId;
|
|
1144
|
+
this.attributed = wire.attributed;
|
|
1145
|
+
this.ambassadorMemberId = wire.ambassadorMemberId ?? null;
|
|
1146
|
+
this.attributedAt = wire.attributedAt ?? null;
|
|
1147
|
+
Object.freeze(this);
|
|
1148
|
+
}
|
|
1149
|
+
/** True when nobody holds credit yet, so this member can be claimed. */
|
|
1150
|
+
get isClaimable() {
|
|
1151
|
+
return !this.attributed;
|
|
1152
|
+
}
|
|
1153
|
+
/** True when credit is held by an ambassador OTHER than the one given. */
|
|
1154
|
+
heldBySomeoneOtherThan(ambassadorMemberId) {
|
|
1155
|
+
return this.attributed && this.ambassadorMemberId !== ambassadorMemberId;
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
var MembersAttributionResult = class {
|
|
1159
|
+
attributions;
|
|
1160
|
+
/**
|
|
1161
|
+
* Member ids that matched no member. Read this rather than diffing your input
|
|
1162
|
+
* against the results — every id you sent lands in one bucket or the other.
|
|
1163
|
+
*/
|
|
1164
|
+
notFound;
|
|
1165
|
+
/** @internal */
|
|
1166
|
+
constructor(wire) {
|
|
1167
|
+
this.attributions = Object.freeze(
|
|
1168
|
+
(wire.attributions ?? []).map((a) => new MemberAttribution(a))
|
|
1169
|
+
);
|
|
1170
|
+
this.notFound = Object.freeze([...wire.notFound ?? []]);
|
|
1171
|
+
Object.freeze(this);
|
|
1172
|
+
}
|
|
1173
|
+
/** Attribution for one member id, or `undefined` if it was not returned. */
|
|
1174
|
+
get(memberId) {
|
|
1175
|
+
return this.attributions.find((a) => a.memberId === memberId);
|
|
1176
|
+
}
|
|
1177
|
+
/** Members nobody holds credit for yet. */
|
|
1178
|
+
get claimable() {
|
|
1179
|
+
return this.attributions.filter((a) => a.isClaimable);
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
var AttributionResult = class {
|
|
1183
|
+
/** How many members were newly attributed by this request. */
|
|
1184
|
+
attributed;
|
|
1185
|
+
/** One entry per member id supplied, in the order supplied. */
|
|
1186
|
+
results;
|
|
1187
|
+
/** @internal */
|
|
1188
|
+
constructor(wire) {
|
|
1189
|
+
this.attributed = wire.attributed;
|
|
1190
|
+
this.results = Object.freeze(
|
|
1191
|
+
(wire.results ?? []).map((r) => Object.freeze({ memberId: r.memberId, outcome: r.outcome }))
|
|
1192
|
+
);
|
|
1193
|
+
Object.freeze(this);
|
|
1194
|
+
}
|
|
1195
|
+
/** Member ids with the given outcome. */
|
|
1196
|
+
withOutcome(outcome) {
|
|
1197
|
+
return this.results.filter((r) => r.outcome === outcome).map((r) => r.memberId);
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Members already credited to somebody. These are the ones worth a human
|
|
1201
|
+
* look — it may be your own host, or it may be another ambassador.
|
|
1202
|
+
*/
|
|
1203
|
+
get alreadyAttributed() {
|
|
1204
|
+
return this.withOutcome("already_attributed");
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Members rejected because their account pre-dates the event's registration
|
|
1208
|
+
* page. The event did not recruit them, so no credit is due.
|
|
1209
|
+
*/
|
|
1210
|
+
get predatedEvent() {
|
|
1211
|
+
return this.withOutcome("account_predates_event");
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
// src/resources/referrals.ts
|
|
1216
|
+
var MAX_IDS_PER_READ = 100;
|
|
1217
|
+
var MAX_IDS_PER_WRITE = 500;
|
|
1218
|
+
var ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
1219
|
+
var ReferralsResource = class {
|
|
1220
|
+
#http;
|
|
1221
|
+
/** @internal */
|
|
1222
|
+
constructor(http) {
|
|
1223
|
+
this.#http = http;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Who currently earns referral credit for these members.
|
|
1227
|
+
*
|
|
1228
|
+
* Use this before {@link attribute} to tell the two cases apart that matter:
|
|
1229
|
+
* a member already credited to your own event host (nothing to do) and one
|
|
1230
|
+
* credited to a different ambassador (a person should look, because claiming
|
|
1231
|
+
* it takes credit from them).
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```ts
|
|
1235
|
+
* const result = await client.referrals.get([4873327, 4873328]);
|
|
1236
|
+
*
|
|
1237
|
+
* for (const a of result.claimable) {
|
|
1238
|
+
* console.log(a.memberId, 'has no credit yet');
|
|
1239
|
+
* }
|
|
1240
|
+
* console.log('no such member:', result.notFound);
|
|
1241
|
+
* ```
|
|
1242
|
+
*
|
|
1243
|
+
* @throws {@link ValidationError} If the list is empty or exceeds 100 ids.
|
|
1244
|
+
*/
|
|
1245
|
+
async get(memberIds) {
|
|
1246
|
+
if (memberIds.length === 0) {
|
|
1247
|
+
throw new ValidationError("At least one member id is required");
|
|
1248
|
+
}
|
|
1249
|
+
if (memberIds.length > MAX_IDS_PER_READ) {
|
|
1250
|
+
throw new ValidationError(`Maximum ${MAX_IDS_PER_READ} member ids per request`);
|
|
1251
|
+
}
|
|
1252
|
+
const wire = await this.#http.request({
|
|
1253
|
+
method: "GET",
|
|
1254
|
+
path: "/partner/members/attribution",
|
|
1255
|
+
query: { memberIds: memberIds.join(",") }
|
|
1256
|
+
});
|
|
1257
|
+
return new MembersAttributionResult({
|
|
1258
|
+
attributions: wire?.attributions ?? [],
|
|
1259
|
+
notFound: wire?.notFound ?? []
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Credit an ambassador for players their event recruited.
|
|
1264
|
+
*
|
|
1265
|
+
* `registrationPublishedAt` is the date the event's registration page was
|
|
1266
|
+
* **first published**. Accounts created before it did not come from the event
|
|
1267
|
+
* and are rejected with `account_predates_event`. VAIR applies that rule
|
|
1268
|
+
* itself, so every partner is held to the same one.
|
|
1269
|
+
*
|
|
1270
|
+
* VAIR cannot verify the date — it holds no record of your registration pages —
|
|
1271
|
+
* so the value you send is recorded for audit. Send the real one.
|
|
1272
|
+
*
|
|
1273
|
+
* Safe to retry: attribution is one-per-player forever, enforced by the
|
|
1274
|
+
* database, so a resubmitted player returns `already_attributed` and nothing
|
|
1275
|
+
* changes.
|
|
1276
|
+
*
|
|
1277
|
+
* @example
|
|
1278
|
+
* ```ts
|
|
1279
|
+
* const result = await client.referrals.attribute({
|
|
1280
|
+
* referralCode: 'hillhurst-open',
|
|
1281
|
+
* registrationPublishedAt: '2026-08-01',
|
|
1282
|
+
* memberIds: [4873327, 4873328],
|
|
1283
|
+
* });
|
|
1284
|
+
*
|
|
1285
|
+
* console.log(result.attributed, 'newly credited');
|
|
1286
|
+
* console.log('need a human:', result.alreadyAttributed);
|
|
1287
|
+
* console.log('too old to credit:', result.predatedEvent);
|
|
1288
|
+
* ```
|
|
1289
|
+
*
|
|
1290
|
+
* @throws {@link ValidationError} If the list is empty or exceeds 500 ids, or
|
|
1291
|
+
* the date is not `YYYY-MM-DD`.
|
|
1292
|
+
*/
|
|
1293
|
+
async attribute(input) {
|
|
1294
|
+
if (!input.referralCode.trim()) {
|
|
1295
|
+
throw new ValidationError("A referral code is required");
|
|
1296
|
+
}
|
|
1297
|
+
if (!ISO_DATE.test(input.registrationPublishedAt)) {
|
|
1298
|
+
throw new ValidationError(
|
|
1299
|
+
"registrationPublishedAt must be a calendar date formatted YYYY-MM-DD"
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
if (input.memberIds.length === 0) {
|
|
1303
|
+
throw new ValidationError("At least one member id is required");
|
|
1304
|
+
}
|
|
1305
|
+
if (input.memberIds.length > MAX_IDS_PER_WRITE) {
|
|
1306
|
+
throw new ValidationError(`Maximum ${MAX_IDS_PER_WRITE} member ids per request`);
|
|
1307
|
+
}
|
|
1308
|
+
const wire = await this.#http.request({
|
|
1309
|
+
method: "POST",
|
|
1310
|
+
path: "/partner/ambassador/attribution",
|
|
1311
|
+
body: {
|
|
1312
|
+
referralCode: input.referralCode.trim(),
|
|
1313
|
+
registrationPublishedAt: input.registrationPublishedAt,
|
|
1314
|
+
memberIds: [...input.memberIds]
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
return new AttributionResult({
|
|
1318
|
+
attributed: wire?.attributed ?? 0,
|
|
1319
|
+
results: wire?.results ?? []
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
|
|
931
1324
|
// src/models/webhook-delivery.ts
|
|
932
1325
|
var WebhookDelivery = class {
|
|
933
1326
|
id;
|
|
@@ -1028,6 +1421,14 @@ var ENVIRONMENTS = Object.freeze({
|
|
|
1028
1421
|
local: "http://localhost:3001/api/v1"
|
|
1029
1422
|
});
|
|
1030
1423
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
1424
|
+
function readEnv(name) {
|
|
1425
|
+
try {
|
|
1426
|
+
if (typeof process === "undefined") return void 0;
|
|
1427
|
+
return process.env?.[name];
|
|
1428
|
+
} catch {
|
|
1429
|
+
return void 0;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1031
1432
|
var Vairified = class {
|
|
1032
1433
|
/** The resolved API key this client is using. */
|
|
1033
1434
|
apiKey;
|
|
@@ -1047,9 +1448,14 @@ var Vairified = class {
|
|
|
1047
1448
|
leaderboard;
|
|
1048
1449
|
/** Webhook delivery inspection — deliveries. */
|
|
1049
1450
|
webhooks;
|
|
1451
|
+
/**
|
|
1452
|
+
* Read and record ambassador referral credit. Each method needs its own
|
|
1453
|
+
* per-partner permission — see {@link ReferralsResource}.
|
|
1454
|
+
*/
|
|
1455
|
+
referrals;
|
|
1050
1456
|
#transport;
|
|
1051
1457
|
constructor(options = {}) {
|
|
1052
|
-
const apiKey = options.apiKey ??
|
|
1458
|
+
const apiKey = options.apiKey ?? readEnv("VAIRIFIED_API_KEY") ?? "";
|
|
1053
1459
|
if (apiKey.length === 0) {
|
|
1054
1460
|
throw new Error("API key required. Pass { apiKey } or set VAIRIFIED_API_KEY.");
|
|
1055
1461
|
}
|
|
@@ -1058,7 +1464,7 @@ var Vairified = class {
|
|
|
1058
1464
|
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
1059
1465
|
this.env = options.env ?? "production";
|
|
1060
1466
|
} else {
|
|
1061
|
-
const envName = options.env ??
|
|
1467
|
+
const envName = options.env ?? readEnv("VAIRIFIED_ENV") ?? "production";
|
|
1062
1468
|
if (options.env && !(envName in ENVIRONMENTS)) {
|
|
1063
1469
|
throw new Error(
|
|
1064
1470
|
`Unknown environment: ${envName}. Use one of: ${Object.keys(ENVIRONMENTS).join(", ")}`
|
|
@@ -1079,6 +1485,7 @@ var Vairified = class {
|
|
|
1079
1485
|
this.oauth = new OAuthResource(this.#transport);
|
|
1080
1486
|
this.leaderboard = new LeaderboardResource(this.#transport);
|
|
1081
1487
|
this.webhooks = new WebhooksResource(this.#transport);
|
|
1488
|
+
this.referrals = new ReferralsResource(this.#transport);
|
|
1082
1489
|
}
|
|
1083
1490
|
/**
|
|
1084
1491
|
* API usage statistics for the current API key.
|
|
@@ -1121,7 +1528,9 @@ export {
|
|
|
1121
1528
|
MatchBatchResult,
|
|
1122
1529
|
MatchesResource,
|
|
1123
1530
|
Member,
|
|
1531
|
+
MemberEmailMatch,
|
|
1124
1532
|
MemberSportMap,
|
|
1533
|
+
MembersByEmailResult,
|
|
1125
1534
|
MembersResource,
|
|
1126
1535
|
NotFoundError,
|
|
1127
1536
|
OAuthError,
|