@spritz-finance/service-client 0.27.0 → 0.29.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.
@@ -1,7 +1,16 @@
1
1
  export * as GrowthClient from "./growthServiceClient";
2
2
  import { PayableAccountType } from "../lib/graphClient/generated";
3
- import { PointsRedemption, PointsRedemptionOption } from "./types";
3
+ import { PointsRedemption, PointsRedemptionOption, ReferrerAccount } from "./types";
4
+ /**
5
+ * @deprecated Returns the referrer's email address, which can belong to several
6
+ * accounts. Use `getUserReferrerAccount` and resolve the referrer by `userId`.
7
+ */
4
8
  export declare function getUserReferrer(userId: string): Promise<string | null>;
9
+ /**
10
+ * The account that referred `userId`, or `null` when the user has no referral
11
+ * row or was not referred.
12
+ */
13
+ export declare function getUserReferrerAccount(userId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<ReferrerAccount | null>>;
5
14
  export declare function initializePointsRedemption(input: {
6
15
  userId: string;
7
16
  paymentRequestId: string;
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.GrowthClient = void 0;
37
37
  exports.getUserReferrer = getUserReferrer;
38
+ exports.getUserReferrerAccount = getUserReferrerAccount;
38
39
  exports.initializePointsRedemption = initializePointsRedemption;
39
40
  exports.getPointsRedemptionOption = getPointsRedemptionOption;
40
41
  exports.validatePointsRedemption = validatePointsRedemption;
@@ -42,11 +43,25 @@ exports.confirmPointsRedemption = confirmPointsRedemption;
42
43
  exports.GrowthClient = __importStar(require("./growthServiceClient"));
43
44
  const serviceClient_1 = require("../serviceClient");
44
45
  const GROWTH_ENDPOINT = "/growth";
46
+ const GROWTH_SERVICE_API_ENDPOINT = "/v2/growth/api";
47
+ /**
48
+ * @deprecated Returns the referrer's email address, which can belong to several
49
+ * accounts. Use `getUserReferrerAccount` and resolve the referrer by `userId`.
50
+ */
45
51
  async function getUserReferrer(userId) {
46
52
  return serviceClient_1.baseClient
47
53
  .get(`${GROWTH_ENDPOINT}/referrals/referrer/${userId}`)
48
54
  .then((res) => res.data);
49
55
  }
56
+ /**
57
+ * The account that referred `userId`, or `null` when the user has no referral
58
+ * row or was not referred.
59
+ */
60
+ async function getUserReferrerAccount(userId) {
61
+ return serviceClient_1.baseClient
62
+ .get(`${GROWTH_SERVICE_API_ENDPOINT}/referrals/${encodeURIComponent(userId)}/referrer`)
63
+ .then((res) => res.data);
64
+ }
50
65
  async function initializePointsRedemption(input) {
51
66
  return serviceClient_1.baseClient
52
67
  .post(`${GROWTH_ENDPOINT}/v2/points/redemption/initialize`, input)
@@ -34,3 +34,12 @@ export interface PointsRedemptionOption {
34
34
  accountTypes?: PayableAccountType[];
35
35
  redeemDescription?: string;
36
36
  }
37
+ /**
38
+ * The account that referred a user, as `GrowthClient.getUserReferrerAccount`
39
+ * returns it. Resolve the referrer by `userId`; `email` is the address growth
40
+ * keeps on the referral row and identifies no account on its own.
41
+ */
42
+ export type ReferrerAccount = {
43
+ userId: string;
44
+ email: string | null;
45
+ };
@@ -1,5 +1,5 @@
1
1
  export * as PlatformClient from "./platformServiceClient";
2
- import { CreateTokenizationData, CreateTokenizationRequest, IssueCardPayoutData, IssueCardPayoutRequest, IssuePayoutData, IssuePayoutRequest, IntegratorUsageKey, IntegratorUsageOperation, IntegratorUsageSummary, MTBalancesData, PlaidTreasuryBalancesData, RelayCheckbookCardData, RelayCheckbookCardRequest, ReleaseIntegratorUsageRequest, ReserveIntegratorUsageRequest, SendPaymentData, SendPaymentRequest, TabapayBalancesResponse, TabapayFundingRequirementResponse, ValidateBillData, ValidateBillRequest } from "./types";
2
+ import { CreateTokenizationData, CreateTokenizationRequest, IssueCardPayoutData, IssueCardPayoutRequest, IssuePayoutData, IssuePayoutRequest, IntegratorUsageKey, IntegratorUsageOperation, IntegratorUsageSummary, MTBalancesData, PersonByUserData, PlaidTreasuryBalancesData, RelayCheckbookCardData, RelayCheckbookCardRequest, ReleaseIntegratorUsageRequest, ReserveIntegratorUsageRequest, SendPaymentData, SendPaymentRequest, TabapayBalancesResponse, TabapayFundingRequirementResponse, ValidateBillData, ValidateBillRequest } from "./types";
3
3
  export declare function validateBill(request: ValidateBillRequest): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<ValidateBillData>>;
4
4
  export declare function tabapayBalances(): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<TabapayBalancesResponse>>;
5
5
  export declare function tabapayFundingRequirement(currency?: string): Promise<TabapayFundingRequirementResponse>;
@@ -37,3 +37,9 @@ export declare function reserveIntegratorUsage(request: ReserveIntegratorUsageRe
37
37
  export declare function commitIntegratorUsage(key: IntegratorUsageKey): Promise<IntegratorUsageOperation>;
38
38
  export declare function releaseIntegratorUsage(request: ReleaseIntegratorUsageRequest): Promise<IntegratorUsageOperation>;
39
39
  export declare function getIntegratorUsage(integratorId: string): Promise<IntegratorUsageSummary>;
40
+ /**
41
+ * Person membership of an account as platform holds it. An account without a
42
+ * Person answers on 2xx too (`outcome: "none"`), so a rejection here is an
43
+ * outage, never "no Person".
44
+ */
45
+ export declare function getPersonByUser(userId: string): Promise<PersonByUserData>;
@@ -51,6 +51,7 @@ exports.reserveIntegratorUsage = reserveIntegratorUsage;
51
51
  exports.commitIntegratorUsage = commitIntegratorUsage;
52
52
  exports.releaseIntegratorUsage = releaseIntegratorUsage;
53
53
  exports.getIntegratorUsage = getIntegratorUsage;
54
+ exports.getPersonByUser = getPersonByUser;
54
55
  exports.PlatformClient = __importStar(require("./platformServiceClient"));
55
56
  const axios_1 = __importDefault(require("axios"));
56
57
  // @ts-expect-error no type declarations for axios-token-interceptor
@@ -174,3 +175,14 @@ async function getIntegratorUsage(integratorId) {
174
175
  .get(`${INTEGRATOR_USAGE_ENDPOINT}/integrators/${encodeURIComponent(integratorId)}`)
175
176
  .then((res) => res.data);
176
177
  }
178
+ const PERSONS_ENDPOINT = "/v1/persons";
179
+ /**
180
+ * Person membership of an account as platform holds it. An account without a
181
+ * Person answers on 2xx too (`outcome: "none"`), so a rejection here is an
182
+ * outage, never "no Person".
183
+ */
184
+ async function getPersonByUser(userId) {
185
+ return platformClient
186
+ .get(`${PERSONS_ENDPOINT}/by-user/${encodeURIComponent(userId)}`)
187
+ .then((res) => res.data);
188
+ }
@@ -275,3 +275,26 @@ export type IntegratorUsageSummary = {
275
275
  remainingTransactionCount?: number;
276
276
  remainingVolumeUsd?: string;
277
277
  };
278
+ /**
279
+ * How an account relates to a Person: `linked` to other accounts, `distinct`
280
+ * (the only account of its Person) or `none` (no Person).
281
+ */
282
+ export type PersonOutcome = "linked" | "distinct" | "none";
283
+ /**
284
+ * How an account joined its Person: `sole` when its own verification made the
285
+ * Person, `key_match` when it joined a Person already holding one of its
286
+ * verified identifiers. A key match is not proof that the accounts are one
287
+ * human.
288
+ */
289
+ export type PersonMembership = "sole" | "key_match";
290
+ /**
291
+ * `GET /v1/persons/by-user/:userId`: the account's Person as platform holds it.
292
+ * `personId` is internal and is never shown to partners.
293
+ */
294
+ export interface PersonByUserData {
295
+ personId: string | null;
296
+ outcome: PersonOutcome;
297
+ /** Every account of the Person, this one included; empty when the account has no Person. */
298
+ memberUserIds: string[];
299
+ membership: PersonMembership | null;
300
+ }
@@ -13,12 +13,57 @@ export interface User {
13
13
  createdAt: string;
14
14
  deleted: boolean;
15
15
  integratorId?: string | null;
16
+ loginMode?: "cognito" | "headless";
17
+ previousEmails?: string[];
16
18
  allNotificationPreferences: {
17
19
  type: NotificationType;
18
20
  email: boolean;
19
21
  mobile: boolean;
20
22
  }[];
21
23
  }
24
+ /**
25
+ * Tenant key of an account that has no home integrator. An email address can
26
+ * be held by one account per tenant, so every email lookup names its tenant:
27
+ * the integrator id for partner accounts, this value for Spritz-native ones.
28
+ */
29
+ export declare const NATIVE_TENANT = "native";
30
+ /**
31
+ * The tenant an account's email lives in: its home `integratorId`, or
32
+ * `NATIVE_TENANT` when it has none. Pass the result as the `tenant` of
33
+ * `UsersClient.findByEmailInTenant`.
34
+ */
35
+ export declare function tenantKeyFor(account: Pick<User, "integratorId">): string;
36
+ /** Codes the users service puts in `error.code` of its failure envelope. */
37
+ export declare const UsersFailureCode: {
38
+ /**
39
+ * `UsersClient.findByEmail`: more than one live account holds the address,
40
+ * so no single account can be returned. Name the tenant with
41
+ * `findByEmailInTenant`, or list the holders with `listByEmail` and choose.
42
+ */
43
+ readonly AmbiguousEmail: "AMBIGUOUS_EMAIL";
44
+ };
45
+ /**
46
+ * One account that holds, or held, an email address: a row of
47
+ * `UsersClient.listByEmail`. Deliberately thin — enough to pick an account
48
+ * explicitly (id and tenant) and to tell live accounts from tombstones.
49
+ */
50
+ export type UserEmailAccount = {
51
+ id: string;
52
+ /** The account's current address. */
53
+ email: string | null;
54
+ /** Home tenant; `null` for Spritz-native accounts. */
55
+ integratorId: string | null;
56
+ deleted: boolean;
57
+ createdAt: string | null;
58
+ /**
59
+ * `current` when the queried address is the account's email, `previous` when
60
+ * the account changed away from it.
61
+ */
62
+ emailMatch: "current" | "previous";
63
+ };
64
+ export type UsersByEmailData = {
65
+ users: UserEmailAccount[];
66
+ };
22
67
  export type IntegratorWebhook = {
23
68
  id: string;
24
69
  integratorId: string;
@@ -1,9 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotificationType = void 0;
3
+ exports.UsersFailureCode = exports.NATIVE_TENANT = exports.NotificationType = void 0;
4
+ exports.tenantKeyFor = tenantKeyFor;
4
5
  var NotificationType;
5
6
  (function (NotificationType) {
6
7
  NotificationType["CardTransactionApproved"] = "cardTransaction.approved";
7
8
  NotificationType["CardTransactionDeclined"] = "cardTransaction.declined";
8
9
  NotificationType["CreditAdded"] = "credit.added";
9
10
  })(NotificationType || (exports.NotificationType = NotificationType = {}));
11
+ /**
12
+ * Tenant key of an account that has no home integrator. An email address can
13
+ * be held by one account per tenant, so every email lookup names its tenant:
14
+ * the integrator id for partner accounts, this value for Spritz-native ones.
15
+ */
16
+ exports.NATIVE_TENANT = "native";
17
+ /**
18
+ * The tenant an account's email lives in: its home `integratorId`, or
19
+ * `NATIVE_TENANT` when it has none. Pass the result as the `tenant` of
20
+ * `UsersClient.findByEmailInTenant`.
21
+ */
22
+ function tenantKeyFor(account) {
23
+ var _a, _b;
24
+ return (_b = (_a = account.integratorId) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : exports.NATIVE_TENANT;
25
+ }
26
+ /** Codes the users service puts in `error.code` of its failure envelope. */
27
+ exports.UsersFailureCode = {
28
+ /**
29
+ * `UsersClient.findByEmail`: more than one live account holds the address,
30
+ * so no single account can be returned. Name the tenant with
31
+ * `findByEmailInTenant`, or list the holders with `listByEmail` and choose.
32
+ */
33
+ AmbiguousEmail: "AMBIGUOUS_EMAIL",
34
+ };
@@ -1,10 +1,34 @@
1
1
  export * as UsersClient from "./usersServiceClient";
2
- import { Integrator, IntegratorReference, IntegratorWebhook, User } from "./types";
2
+ import { Integrator, IntegratorReference, IntegratorWebhook, User, UsersByEmailData } from "./types";
3
3
  export declare function getActiveUsers(): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<string[]>>;
4
4
  export declare function getUserById(id: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User>>;
5
5
  export declare function setMembership(userId: string, membership: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User>>;
6
6
  export declare function findOrInitialize(email: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User>>;
7
+ /**
8
+ * @deprecated Single-valued lookup across every tenant. An address can be held
9
+ * by one account per home tenant, so there is not always one answer: when more
10
+ * than one live account holds the email the users service answers the failure
11
+ * envelope `{ status: "failure", error: { code: "AMBIGUOUS_EMAIL" } }`
12
+ * (`UsersFailureCode.AmbiguousEmail`) instead of picking one, so a caller fails
13
+ * closed rather than act on an arbitrary account. Use `findByEmailInTenant`
14
+ * when the tenant is known, or `listByEmail` and choose explicitly.
15
+ */
7
16
  export declare function findByEmail(email: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User | null>>;
17
+ /**
18
+ * The one account holding `email` in `tenant`: an integrator id for partner
19
+ * accounts, `NATIVE_TENANT` for Spritz-native ones (`tenantKeyFor` derives it
20
+ * from an account already in hand). One account can hold an address per
21
+ * tenant, so this is the single-valued email lookup that stays unambiguous.
22
+ * `null` when the tenant has no such account.
23
+ */
24
+ export declare function findByEmailInTenant(email: string, tenant: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User | null>>;
25
+ /**
26
+ * Every account that holds `email` now or held it before an email change,
27
+ * across all tenants and including deleted ones. For tooling and automation
28
+ * that must pick an account explicitly: when more than one live row matches,
29
+ * refuse and ask for an account id rather than take the first.
30
+ */
31
+ export declare function listByEmail(email: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<UsersByEmailData>>;
8
32
  export declare function validateAdIdentifiers(adIdentifiers?: {
9
33
  gclid?: string;
10
34
  twclid?: string;
@@ -39,6 +39,8 @@ exports.getUserById = getUserById;
39
39
  exports.setMembership = setMembership;
40
40
  exports.findOrInitialize = findOrInitialize;
41
41
  exports.findByEmail = findByEmail;
42
+ exports.findByEmailInTenant = findByEmailInTenant;
43
+ exports.listByEmail = listByEmail;
42
44
  exports.validateAdIdentifiers = validateAdIdentifiers;
43
45
  exports.getIntegratorWebhooks = getIntegratorWebhooks;
44
46
  exports.getIntegrator = getIntegrator;
@@ -70,11 +72,44 @@ async function findOrInitialize(email) {
70
72
  })
71
73
  .then((res) => res.data);
72
74
  }
75
+ /**
76
+ * @deprecated Single-valued lookup across every tenant. An address can be held
77
+ * by one account per home tenant, so there is not always one answer: when more
78
+ * than one live account holds the email the users service answers the failure
79
+ * envelope `{ status: "failure", error: { code: "AMBIGUOUS_EMAIL" } }`
80
+ * (`UsersFailureCode.AmbiguousEmail`) instead of picking one, so a caller fails
81
+ * closed rather than act on an arbitrary account. Use `findByEmailInTenant`
82
+ * when the tenant is known, or `listByEmail` and choose explicitly.
83
+ */
73
84
  async function findByEmail(email) {
74
85
  return serviceClient_1.baseClient
75
86
  .get(`${NEW_USER_ENDPOINT}/users?email=${encodeURIComponent(email)}`)
76
87
  .then((res) => res.data);
77
88
  }
89
+ /**
90
+ * The one account holding `email` in `tenant`: an integrator id for partner
91
+ * accounts, `NATIVE_TENANT` for Spritz-native ones (`tenantKeyFor` derives it
92
+ * from an account already in hand). One account can hold an address per
93
+ * tenant, so this is the single-valued email lookup that stays unambiguous.
94
+ * `null` when the tenant has no such account.
95
+ */
96
+ async function findByEmailInTenant(email, tenant) {
97
+ const query = `email=${encodeURIComponent(email)}&tenant=${encodeURIComponent(tenant)}`;
98
+ return serviceClient_1.baseClient
99
+ .get(`${NEW_USER_ENDPOINT}/users/by-email?${query}`)
100
+ .then((res) => res.data);
101
+ }
102
+ /**
103
+ * Every account that holds `email` now or held it before an email change,
104
+ * across all tenants and including deleted ones. For tooling and automation
105
+ * that must pick an account explicitly: when more than one live row matches,
106
+ * refuse and ask for an account id rather than take the first.
107
+ */
108
+ async function listByEmail(email) {
109
+ return serviceClient_1.baseClient
110
+ .get(`${NEW_USER_ENDPOINT}/users/all-by-email?email=${encodeURIComponent(email)}`)
111
+ .then((res) => res.data);
112
+ }
78
113
  async function validateAdIdentifiers(adIdentifiers) {
79
114
  return serviceClient_1.baseClient
80
115
  .post(`${NEW_USER_ENDPOINT}/users/ad-identifiers/validations`, adIdentifiers)
@@ -11,6 +11,36 @@ type DebitCardPayableType = {
11
11
  type VCCPayableType = {
12
12
  type: string;
13
13
  };
14
+ /**
15
+ * Why an account was tagged as a duplicate: the stored values of verification's
16
+ * `DuplicateSignal`, as the raw document carries them.
17
+ */
18
+ export type IdentityDuplicateSignal = "persona_document" | "national_id" | "document" | "name_dob" | "phone_address" | "phone" | "manual_override" | "duplicate_failure";
19
+ /**
20
+ * Set the first time an account is found to share an identity with another one
21
+ * and never cleared: a plain "has ever been marked as a duplicate" tag that
22
+ * accumulates signals and matched accounts. A candidate signal, not proof that
23
+ * two accounts belong to one person.
24
+ */
25
+ export type IdentityDuplicateMark = {
26
+ firstMarkedAt: string;
27
+ lastMarkedAt: string;
28
+ signals: IdentityDuplicateSignal[];
29
+ matchedUserIds: string[];
30
+ };
31
+ /**
32
+ * Stored value of verification's `ManualOverrideReason`. The raw document
33
+ * carries this snake_case value, not the GraphQL enum name.
34
+ */
35
+ export type IdentityManualOverrideReason = "duplicate_identity";
36
+ /** Staff approved the account past a block; present only when they did. */
37
+ export type IdentityManualOverrideRecord = {
38
+ reason: IdentityManualOverrideReason;
39
+ approvedAt: string;
40
+ approvedByUserId: string;
41
+ approvedByEmail?: string;
42
+ note: string;
43
+ };
14
44
  export type Verification = {
15
45
  id: string;
16
46
  userId: string;
@@ -35,6 +65,8 @@ export type Verification = {
35
65
  countryCode: string;
36
66
  };
37
67
  };
68
+ duplicateMark?: IdentityDuplicateMark;
69
+ manualOverride?: IdentityManualOverrideRecord;
38
70
  };
39
71
  bankAccount: {
40
72
  status: VerificationModuleStatus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spritz-finance/service-client",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "gitHead": "06f8e96b7b38c34df26a38da329331940675e4f8",
5
5
  "description": "Service client",
6
6
  "license": "ISC",