@memberjunction/actions-apollo 6.1.0-edge.4 → 6.1.0-edge.5

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 (46) hide show
  1. package/README.md +79 -0
  2. package/dist/__tests__/apollo-lists.test.d.ts +2 -0
  3. package/dist/__tests__/apollo-lists.test.d.ts.map +1 -0
  4. package/dist/__tests__/apollo-lists.test.js +957 -0
  5. package/dist/__tests__/apollo-lists.test.js.map +1 -0
  6. package/dist/config.d.ts +10 -0
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +10 -0
  9. package/dist/config.js.map +1 -1
  10. package/dist/generic/apollo-lists.types.d.ts +246 -0
  11. package/dist/generic/apollo-lists.types.d.ts.map +1 -0
  12. package/dist/generic/apollo-lists.types.js +42 -0
  13. package/dist/generic/apollo-lists.types.js.map +1 -0
  14. package/dist/index.d.ts +8 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +11 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/lists/ApolloListActions.d.ts +49 -0
  19. package/dist/lists/ApolloListActions.d.ts.map +1 -0
  20. package/dist/lists/ApolloListActions.js +135 -0
  21. package/dist/lists/ApolloListActions.js.map +1 -0
  22. package/dist/lists/ApolloMoveActions.d.ts +33 -0
  23. package/dist/lists/ApolloMoveActions.d.ts.map +1 -0
  24. package/dist/lists/ApolloMoveActions.js +272 -0
  25. package/dist/lists/ApolloMoveActions.js.map +1 -0
  26. package/dist/lists/ApolloRESTBaseAction.d.ts +49 -0
  27. package/dist/lists/ApolloRESTBaseAction.d.ts.map +1 -0
  28. package/dist/lists/ApolloRESTBaseAction.js +70 -0
  29. package/dist/lists/ApolloRESTBaseAction.js.map +1 -0
  30. package/dist/lists/ApolloRESTClient.d.ts +136 -0
  31. package/dist/lists/ApolloRESTClient.d.ts.map +1 -0
  32. package/dist/lists/ApolloRESTClient.js +561 -0
  33. package/dist/lists/ApolloRESTClient.js.map +1 -0
  34. package/dist/lists/ApolloSearchActions.d.ts +64 -0
  35. package/dist/lists/ApolloSearchActions.d.ts.map +1 -0
  36. package/dist/lists/ApolloSearchActions.js +239 -0
  37. package/dist/lists/ApolloSearchActions.js.map +1 -0
  38. package/dist/lists/credentials.d.ts +57 -0
  39. package/dist/lists/credentials.d.ts.map +1 -0
  40. package/dist/lists/credentials.js +161 -0
  41. package/dist/lists/credentials.js.map +1 -0
  42. package/dist/lists/params.d.ts +61 -0
  43. package/dist/lists/params.d.ts.map +1 -0
  44. package/dist/lists/params.js +113 -0
  45. package/dist/lists/params.js.map +1 -0
  46. package/package.json +8 -7
@@ -0,0 +1,135 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ /**
8
+ * Apollo label (list) actions: read the lists, and create one.
9
+ *
10
+ * Both need a MASTER Apollo key — the labels endpoints 403 on scoped keys, which
11
+ * is worth knowing before wiring these into a workflow, because the failure is
12
+ * indistinguishable from a bad key until you read the message.
13
+ */
14
+ import { RegisterClass } from '@memberjunction/global';
15
+ import { LogError, LogStatus } from '@memberjunction/core';
16
+ import { BaseAction } from '@memberjunction/actions';
17
+ import { ApolloRESTBaseAction } from './ApolloRESTBaseAction.js';
18
+ import { getParam } from './params.js';
19
+ /**
20
+ * Lists the Apollo labels — lists and tags — with each one's kind
21
+ * ('accounts' | 'contacts') and cached member count.
22
+ *
23
+ * This is the first call in any list workflow, because every other action here
24
+ * addresses lists by exact name and this is what tells you the names. Read-only.
25
+ *
26
+ * Inputs:
27
+ * - CompanyID (optional) resolve the key from this company's Apollo credential
28
+ * instead of APOLLO_API_KEY
29
+ *
30
+ * Outputs:
31
+ * - Lists array of { id, name, kind, cachedCount, createdAt, updatedAt }
32
+ * - Count number of labels
33
+ * - KeySource 'credential' | 'environment' — which path supplied the key
34
+ */
35
+ let ApolloGetListsAction = class ApolloGetListsAction extends ApolloRESTBaseAction {
36
+ async InternalRunAction(params) {
37
+ const { resolved, error } = await this.ResolveClient(params);
38
+ if (error)
39
+ return error;
40
+ try {
41
+ const lists = await resolved.client.listLabels();
42
+ params.Params.push({ Name: 'Lists', Type: 'Output', Value: lists }, { Name: 'Count', Type: 'Output', Value: lists.length }, { Name: 'KeySource', Type: 'Output', Value: resolved.key.source });
43
+ return {
44
+ Success: true,
45
+ Message: `Apollo lists: ${lists.length} label(s).`,
46
+ ResultCode: 'SUCCESS',
47
+ Params: params.Params,
48
+ };
49
+ }
50
+ catch (err) {
51
+ const msg = err instanceof Error ? err.message : String(err);
52
+ LogError(`ApolloGetLists: ${msg}`);
53
+ return { Success: false, Message: `Error listing Apollo labels: ${msg}`, ResultCode: 'ERROR' };
54
+ }
55
+ }
56
+ };
57
+ ApolloGetListsAction = __decorate([
58
+ RegisterClass(BaseAction, 'ApolloGetListsAction')
59
+ ], ApolloGetListsAction);
60
+ export { ApolloGetListsAction };
61
+ /**
62
+ * Creates an Apollo list (label), idempotently.
63
+ *
64
+ * The existing labels are read first, and a same-named label — matched
65
+ * case-insensitively — is returned as-is with `AlreadyExisted: true` rather than
66
+ * creating a second one. Apollo will happily create two labels with the same name,
67
+ * and once it has, every name-based lookup in this surface becomes ambiguous:
68
+ * `findLabelByName` returns whichever comes first, so half the moves would target
69
+ * one list and half the other. Making create idempotent is what keeps
70
+ * name-addressing sound.
71
+ *
72
+ * Master-key write.
73
+ *
74
+ * Inputs:
75
+ * - ListName (required) the label to create
76
+ * - Modality (optional) 'contacts' (default) | 'accounts' — Apollo rejects a
77
+ * create with no modality, so this is a real choice, not
78
+ * decoration: a contacts label cannot tag accounts
79
+ * - CompanyID (optional) as above
80
+ *
81
+ * Outputs:
82
+ * - ListID / ResolvedListName / AlreadyExisted / Modality / KeySource
83
+ */
84
+ let ApolloCreateListAction = class ApolloCreateListAction extends ApolloRESTBaseAction {
85
+ async InternalRunAction(params) {
86
+ const listName = getParam(params, 'ListName');
87
+ if (!listName)
88
+ return this.MissingField('ListName');
89
+ const rawModality = getParam(params, 'Modality');
90
+ const modality = (rawModality ?? 'contacts').toLowerCase();
91
+ if (modality !== 'contacts' && modality !== 'accounts') {
92
+ return this.Invalid(`Modality must be 'contacts' or 'accounts' (got '${rawModality}').`);
93
+ }
94
+ const { resolved, error } = await this.ResolveClient(params);
95
+ if (error)
96
+ return error;
97
+ try {
98
+ const existingLabels = await resolved.client.listLabels();
99
+ const target = listName.toLowerCase();
100
+ const existing = existingLabels.find((l) => l.name.trim().toLowerCase() === target);
101
+ if (existing) {
102
+ LogStatus(`ApolloCreateList: label '${existing.name}' already exists (id ${existing.id}); not creating a duplicate.`);
103
+ params.Params.push({ Name: 'ListID', Type: 'Output', Value: existing.id }, { Name: 'ResolvedListName', Type: 'Output', Value: existing.name }, { Name: 'AlreadyExisted', Type: 'Output', Value: true }, { Name: 'Modality', Type: 'Output', Value: existing.kind }, { Name: 'KeySource', Type: 'Output', Value: resolved.key.source });
104
+ return {
105
+ Success: true,
106
+ Message: `Apollo list '${existing.name}' already existed (id ${existing.id}); returned without creating a duplicate.`,
107
+ ResultCode: 'SUCCESS',
108
+ Params: params.Params,
109
+ };
110
+ }
111
+ const created = await resolved.client.createLabel(listName, modality);
112
+ LogStatus(`ApolloCreateList: created label '${created.name}' (id ${created.id}, modality ${modality}).`);
113
+ params.Params.push({ Name: 'ListID', Type: 'Output', Value: created.id }, { Name: 'ResolvedListName', Type: 'Output', Value: created.name }, { Name: 'AlreadyExisted', Type: 'Output', Value: false }, { Name: 'Modality', Type: 'Output', Value: created.kind }, { Name: 'KeySource', Type: 'Output', Value: resolved.key.source });
114
+ return {
115
+ Success: true,
116
+ Message: `Created Apollo list '${created.name}' (id ${created.id}).`,
117
+ ResultCode: 'SUCCESS',
118
+ Params: params.Params,
119
+ };
120
+ }
121
+ catch (err) {
122
+ const msg = err instanceof Error ? err.message : String(err);
123
+ LogError(`ApolloCreateList: ${msg}`);
124
+ return { Success: false, Message: `Error creating Apollo list: ${msg}`, ResultCode: 'ERROR' };
125
+ }
126
+ }
127
+ };
128
+ ApolloCreateListAction = __decorate([
129
+ RegisterClass(BaseAction, 'ApolloCreateListAction')
130
+ ], ApolloCreateListAction);
131
+ export { ApolloCreateListAction };
132
+ export function LoadApolloListActions() {
133
+ // Referenced by consumers to keep these registrations from being tree-shaken.
134
+ }
135
+ //# sourceMappingURL=ApolloListActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloListActions.js","sourceRoot":"","sources":["../../src/lists/ApolloListActions.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;GAMG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;;;;;;;;;GAeG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,oBAAoB;IAChD,KAAK,CAAC,iBAAiB,CAAC,MAAuB;QACrD,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC7D,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;QAExB,IAAI,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAEjD,MAAM,CAAC,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E,UAAU,EAAE,SAAS;gBACrB,MAAM,EAAE,MAAM,CAAC,MAAM;aACxB,CAAC;QACN,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,QAAQ,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAC;YACrC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,+BAA+B,GAAG,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;QAClG,CAAC;IACL,CAAC;CACJ,CAAA;AA3DY,sBAAsB;IADlC,aAAa,CAAC,UAAU,EAAE,wBAAwB,CAAC;GACvC,sBAAsB,CA2DlC;;AAED,MAAM,UAAU,qBAAqB;IACjC,8EAA8E;AAClF,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
2
+ import { ApolloRESTBaseAction } from './ApolloRESTBaseAction.js';
3
+ /**
4
+ * Moves accounts from one Apollo list to another.
5
+ *
6
+ * Inputs:
7
+ * - AccountIDs (required) JSON array or comma-separated Apollo account ids
8
+ * - FromList (required) exact source label name
9
+ * - ToList (required) exact destination label name
10
+ * - CompanyID (optional) per-company credential resolution
11
+ *
12
+ * Outputs:
13
+ * - MovedCount / FailedCount / PossiblyStuckCount
14
+ * - Results per-account { id, added, removed, possiblyStuck, error }
15
+ * - NotOnSourcePage supplied ids that were not on page 1 of the source list
16
+ * - KeySource
17
+ *
18
+ * `PARTIAL_FAILURE` means at least one PATCH failed outright. Possibly-stuck
19
+ * records are NOT failures — the write succeeded and Apollo did not honour it.
20
+ */
21
+ export declare class ApolloMoveListAccountsAction extends ApolloRESTBaseAction {
22
+ protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
23
+ }
24
+ /**
25
+ * Moves contacts from one Apollo list to another. Identical semantics to
26
+ * {@link ApolloMoveListAccountsAction}; the id param is `ContactIDs` and the
27
+ * outputs carry contact results.
28
+ */
29
+ export declare class ApolloMoveListContactsAction extends ApolloRESTBaseAction {
30
+ protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
31
+ }
32
+ export declare function LoadApolloMoveActions(): void;
33
+ //# sourceMappingURL=ApolloMoveActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloMoveActions.d.ts","sourceRoot":"","sources":["../../src/lists/ApolloMoveActions.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAExF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA0IjE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBACa,4BAA6B,SAAQ,oBAAoB;cAClD,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAwE1F;AAED;;;;GAIG;AACH,qBACa,4BAA6B,SAAQ,oBAAoB;cAClD,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAuE1F;AAED,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
@@ -0,0 +1,272 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ /**
8
+ * Apollo list-move actions.
9
+ *
10
+ * A move is the only genuinely dangerous thing in this surface, so the two actions
11
+ * below are more cautious than their size suggests:
12
+ *
13
+ * - Both list names are resolved to real labels BEFORE any write. A typo in
14
+ * `ToList` that was only noticed halfway through would leave a batch split
15
+ * across two lists with no record of which half moved.
16
+ * - The source list is re-read to get each record's CURRENT labels. The caller
17
+ * supplies ids, never labels: Apollo replaces the whole label array on every
18
+ * update, so writing a stale set silently strips memberships the record picked
19
+ * up since the caller last looked.
20
+ * - Removes are verified, and records whose remove silently no-op'd are reported
21
+ * rather than retried. Apollo fails this way on roughly 15-17% of removes and
22
+ * an immediate retry flakes the same way; the next page-1 drain sees them
23
+ * carrying both labels and finishes the job.
24
+ *
25
+ * Both require a MASTER Apollo key. There is no delete surface.
26
+ */
27
+ import { RegisterClass } from '@memberjunction/global';
28
+ import { LogError, LogStatus } from '@memberjunction/core';
29
+ import { BaseAction } from '@memberjunction/actions';
30
+ import { ApolloRESTBaseAction } from './ApolloRESTBaseAction.js';
31
+ import { LIST_NOT_FOUND_HINT, getParam, getParamRaw, parseStringArrayParam } from './params.js';
32
+ /** Apollo's per-page maximum, which is also the widest source page a move can see. */
33
+ const MOVE_SOURCE_PER_PAGE = 100;
34
+ /**
35
+ * Validate the shared inputs. Identical `FromList`/`ToList` is rejected here
36
+ * rather than left to the client, so the caller gets a validation error instead of
37
+ * an exception out of the move engine.
38
+ */
39
+ function parseMoveInputs(params, idsParamName) {
40
+ const idsParsed = parseStringArrayParam(getParamRaw(params, idsParamName), idsParamName);
41
+ if (idsParsed.error !== null) {
42
+ return { inputs: null, error: { Success: false, Message: idsParsed.error, ResultCode: 'VALIDATION_ERROR' } };
43
+ }
44
+ if (idsParsed.value === undefined) {
45
+ return {
46
+ inputs: null,
47
+ error: {
48
+ Success: false,
49
+ Message: `Missing required field: ${idsParamName} (JSON array or comma-separated Apollo ids)`,
50
+ ResultCode: 'MISSING_REQUIRED_FIELDS',
51
+ },
52
+ };
53
+ }
54
+ const fromList = getParam(params, 'FromList');
55
+ if (!fromList) {
56
+ return { inputs: null, error: { Success: false, Message: 'Missing required field: FromList', ResultCode: 'MISSING_REQUIRED_FIELDS' } };
57
+ }
58
+ const toList = getParam(params, 'ToList');
59
+ if (!toList) {
60
+ return { inputs: null, error: { Success: false, Message: 'Missing required field: ToList', ResultCode: 'MISSING_REQUIRED_FIELDS' } };
61
+ }
62
+ if (fromList.toLowerCase() === toList.toLowerCase()) {
63
+ return {
64
+ inputs: null,
65
+ error: {
66
+ Success: false,
67
+ Message: `FromList and ToList are identical ('${fromList}') — nothing to move.`,
68
+ ResultCode: 'VALIDATION_ERROR',
69
+ },
70
+ };
71
+ }
72
+ return { inputs: { ids: idsParsed.value, fromList, toList }, error: null };
73
+ }
74
+ /** Resolve both list names to labels before any write happens. */
75
+ async function resolveBothLabels(client, fromList, toList) {
76
+ const from = await client.findLabelByName(fromList);
77
+ if (!from) {
78
+ return {
79
+ from: null,
80
+ to: null,
81
+ error: {
82
+ Success: false,
83
+ Message: `No Apollo list named '${fromList}' (FromList) was found. ${LIST_NOT_FOUND_HINT}`,
84
+ ResultCode: 'NOT_FOUND',
85
+ },
86
+ };
87
+ }
88
+ const to = await client.findLabelByName(toList);
89
+ if (!to) {
90
+ return {
91
+ from: null,
92
+ to: null,
93
+ error: {
94
+ Success: false,
95
+ Message: `No Apollo list named '${toList}' (ToList) was found. ${LIST_NOT_FOUND_HINT}`,
96
+ ResultCode: 'NOT_FOUND',
97
+ },
98
+ };
99
+ }
100
+ return { from, to, error: null };
101
+ }
102
+ /** The note appended when Apollo's silent-fail removes showed up. */
103
+ function stuckNote(possiblyStuckCount, kind) {
104
+ return possiblyStuckCount > 0
105
+ ? ` ${possiblyStuckCount} ${kind} may be stuck — Apollo's remove reported success without applying. ` +
106
+ `They will resurface on the next page-1 drain carrying both labels; strip the source label then. ` +
107
+ `An immediate retry flakes the same way, which is why this action does not attempt one.`
108
+ : '';
109
+ }
110
+ /**
111
+ * Builds the caller-facing outcome, counting ids that were never ATTEMPTED as well as those that
112
+ * failed.
113
+ *
114
+ * This reads only page 1 of the source list, so ids beyond it land in `notOnSourcePage` and are
115
+ * silently skipped. The previous message was `Moved N of ${toMove.length}` where `toMove` counted
116
+ * only what page 1 contained — so passing 300 ids reported `Moved 100 of 100` with `Success: true`
117
+ * while 200 were never touched. `LogStatus` said so; the caller-facing result did not, and a caller
118
+ * acting on `Success` had no way to discover it.
119
+ *
120
+ * Skipped ids are therefore a PARTIAL_FAILURE, not a success: the caller asked for work that did not
121
+ * happen. `NotOnSourcePage` carries exactly which ones, so a retry is mechanical.
122
+ */
123
+ function moveOutcome(result, attempted, requested, notOnSourcePage, from, to, kind) {
124
+ const skipped = notOnSourcePage.length;
125
+ const incomplete = result.failedCount > 0 || skipped > 0;
126
+ return {
127
+ // Reported against what the caller ASKED for, not against what page 1 happened to contain.
128
+ Success: !incomplete,
129
+ Message: `Moved ${result.movedCount} of ${requested} ${kind} from '${from}' to '${to}'` +
130
+ `${result.failedCount > 0 ? `; ${result.failedCount} failed` : ''}` +
131
+ `${skipped > 0
132
+ ? `; ${skipped} not on page 1 of '${from}' and NOT attempted — see NotOnSourcePage` +
133
+ `${attempted !== requested ? ` (${attempted} attempted)` : ''}`
134
+ : ''}` +
135
+ `.${stuckNote(result.possiblyStuckCount, kind)}`,
136
+ ResultCode: incomplete ? 'PARTIAL_FAILURE' : 'SUCCESS',
137
+ };
138
+ }
139
+ /**
140
+ * Moves accounts from one Apollo list to another.
141
+ *
142
+ * Inputs:
143
+ * - AccountIDs (required) JSON array or comma-separated Apollo account ids
144
+ * - FromList (required) exact source label name
145
+ * - ToList (required) exact destination label name
146
+ * - CompanyID (optional) per-company credential resolution
147
+ *
148
+ * Outputs:
149
+ * - MovedCount / FailedCount / PossiblyStuckCount
150
+ * - Results per-account { id, added, removed, possiblyStuck, error }
151
+ * - NotOnSourcePage supplied ids that were not on page 1 of the source list
152
+ * - KeySource
153
+ *
154
+ * `PARTIAL_FAILURE` means at least one PATCH failed outright. Possibly-stuck
155
+ * records are NOT failures — the write succeeded and Apollo did not honour it.
156
+ */
157
+ let ApolloMoveListAccountsAction = class ApolloMoveListAccountsAction extends ApolloRESTBaseAction {
158
+ async InternalRunAction(params) {
159
+ const parsed = parseMoveInputs(params, 'AccountIDs');
160
+ if (parsed.error)
161
+ return parsed.error;
162
+ const { ids, fromList, toList } = parsed.inputs;
163
+ const { resolved, error } = await this.ResolveClient(params);
164
+ if (error)
165
+ return error;
166
+ try {
167
+ const labels = await resolveBothLabels(resolved.client, fromList, toList);
168
+ if (labels.error)
169
+ return labels.error;
170
+ // Re-read the source list to capture CURRENT labels — page 1, drain-safe.
171
+ const sourcePage = await resolved.client.searchAccounts({ labelIds: [labels.from.id] }, { page: 1, perPage: MOVE_SOURCE_PER_PAGE });
172
+ const byId = new Map(sourcePage.accounts.map((a) => [a.id, a]));
173
+ const toMove = [];
174
+ const notOnSourcePage = [];
175
+ for (const id of new Set(ids)) {
176
+ const account = byId.get(id);
177
+ if (account)
178
+ toMove.push(account);
179
+ else
180
+ notOnSourcePage.push(id);
181
+ }
182
+ if (toMove.length === 0) {
183
+ return {
184
+ Success: false,
185
+ Message: `None of the ${ids.length} supplied account id(s) were found on page 1 of '${labels.from.name}'. ` +
186
+ `They may already have moved, or sit on a later page — re-read page 1, since removals shift pages.`,
187
+ ResultCode: 'NOT_FOUND',
188
+ };
189
+ }
190
+ const result = await resolved.client.moveAccounts(toMove, labels.from.name, labels.to.name, { verify: true });
191
+ LogStatus(`ApolloMoveListAccounts: '${labels.from.name}' → '${labels.to.name}' — ${result.movedCount} moved, ` +
192
+ `${result.possiblyStuckCount} possibly stuck, ${result.failedCount} failed of ${toMove.length} ` +
193
+ `(${notOnSourcePage.length} supplied id(s) not on source page 1).`);
194
+ params.Params.push({ Name: 'MovedCount', Type: 'Output', Value: result.movedCount }, { Name: 'FailedCount', Type: 'Output', Value: result.failedCount }, { Name: 'PossiblyStuckCount', Type: 'Output', Value: result.possiblyStuckCount }, { Name: 'Results', Type: 'Output', Value: result.items }, { Name: 'NotOnSourcePage', Type: 'Output', Value: notOnSourcePage }, { Name: 'KeySource', Type: 'Output', Value: resolved.key.source });
195
+ return {
196
+ ...moveOutcome(result, toMove.length, new Set(ids).size, notOnSourcePage, labels.from.name, labels.to.name, 'account(s)'),
197
+ Params: params.Params,
198
+ };
199
+ }
200
+ catch (err) {
201
+ const msg = err instanceof Error ? err.message : String(err);
202
+ LogError(`ApolloMoveListAccounts: ${msg}`);
203
+ return { Success: false, Message: `Error moving Apollo accounts: ${msg}`, ResultCode: 'ERROR' };
204
+ }
205
+ }
206
+ };
207
+ ApolloMoveListAccountsAction = __decorate([
208
+ RegisterClass(BaseAction, 'ApolloMoveListAccountsAction')
209
+ ], ApolloMoveListAccountsAction);
210
+ export { ApolloMoveListAccountsAction };
211
+ /**
212
+ * Moves contacts from one Apollo list to another. Identical semantics to
213
+ * {@link ApolloMoveListAccountsAction}; the id param is `ContactIDs` and the
214
+ * outputs carry contact results.
215
+ */
216
+ let ApolloMoveListContactsAction = class ApolloMoveListContactsAction extends ApolloRESTBaseAction {
217
+ async InternalRunAction(params) {
218
+ const parsed = parseMoveInputs(params, 'ContactIDs');
219
+ if (parsed.error)
220
+ return parsed.error;
221
+ const { ids, fromList, toList } = parsed.inputs;
222
+ const { resolved, error } = await this.ResolveClient(params);
223
+ if (error)
224
+ return error;
225
+ try {
226
+ const labels = await resolveBothLabels(resolved.client, fromList, toList);
227
+ if (labels.error)
228
+ return labels.error;
229
+ const sourcePage = await resolved.client.searchContacts({ labelIds: [labels.from.id] }, { page: 1, perPage: MOVE_SOURCE_PER_PAGE });
230
+ const byId = new Map(sourcePage.contacts.map((c) => [c.id, c]));
231
+ const toMove = [];
232
+ const notOnSourcePage = [];
233
+ for (const id of new Set(ids)) {
234
+ const contact = byId.get(id);
235
+ if (contact)
236
+ toMove.push(contact);
237
+ else
238
+ notOnSourcePage.push(id);
239
+ }
240
+ if (toMove.length === 0) {
241
+ return {
242
+ Success: false,
243
+ Message: `None of the ${ids.length} supplied contact id(s) were found on page 1 of '${labels.from.name}'. ` +
244
+ `They may already have moved, or sit on a later page — re-read page 1, since removals shift pages.`,
245
+ ResultCode: 'NOT_FOUND',
246
+ };
247
+ }
248
+ const result = await resolved.client.moveContacts(toMove, labels.from.name, labels.to.name, { verify: true });
249
+ LogStatus(`ApolloMoveListContacts: '${labels.from.name}' → '${labels.to.name}' — ${result.movedCount} moved, ` +
250
+ `${result.possiblyStuckCount} possibly stuck, ${result.failedCount} failed of ${toMove.length} ` +
251
+ `(${notOnSourcePage.length} supplied id(s) not on source page 1).`);
252
+ params.Params.push({ Name: 'MovedCount', Type: 'Output', Value: result.movedCount }, { Name: 'FailedCount', Type: 'Output', Value: result.failedCount }, { Name: 'PossiblyStuckCount', Type: 'Output', Value: result.possiblyStuckCount }, { Name: 'Results', Type: 'Output', Value: result.items }, { Name: 'NotOnSourcePage', Type: 'Output', Value: notOnSourcePage }, { Name: 'KeySource', Type: 'Output', Value: resolved.key.source });
253
+ return {
254
+ ...moveOutcome(result, toMove.length, new Set(ids).size, notOnSourcePage, labels.from.name, labels.to.name, 'contact(s)'),
255
+ Params: params.Params,
256
+ };
257
+ }
258
+ catch (err) {
259
+ const msg = err instanceof Error ? err.message : String(err);
260
+ LogError(`ApolloMoveListContacts: ${msg}`);
261
+ return { Success: false, Message: `Error moving Apollo contacts: ${msg}`, ResultCode: 'ERROR' };
262
+ }
263
+ }
264
+ };
265
+ ApolloMoveListContactsAction = __decorate([
266
+ RegisterClass(BaseAction, 'ApolloMoveListContactsAction')
267
+ ], ApolloMoveListContactsAction);
268
+ export { ApolloMoveListContactsAction };
269
+ export function LoadApolloMoveActions() {
270
+ // Referenced by consumers to keep these registrations from being tree-shaken.
271
+ }
272
+ //# sourceMappingURL=ApolloMoveActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloMoveActions.js","sourceRoot":"","sources":["../../src/lists/ApolloMoveActions.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,wBA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AE,eAAe,EAAE,EACnE,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,CACpE,CAAC;YAEF,OAAO;gBACH,GAAG,WAAW,CACV,MAAM,EACN,MAAM,CAAC,MAAM,EACb,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EACjB,eAAe,EACf,MAAM,CAAC,IAAI,CAAC,IAAI,EAChB,MAAM,CAAC,EAAE,CAAC,IAAI,EACd,YAAY,CACf;gBACD,MAAM,EAAE,MAAM,CAAC,MAAM;aACxB,CAAC;QACN,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,QAAQ,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAC;YAC3C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,iCAAiC,GAAG,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;QACpG,CAAC;IACL,CAAC;CACJ,CAAA;AAxEY,4BAA4B;IADxC,aAAa,CAAC,UAAU,EAAE,8BAA8B,CAAC;GAC7C,4BAA4B,CAwExC;;AAED,MAAM,UAAU,qBAAqB;IACjC,8EAA8E;AAClF,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Shared plumbing for the Apollo list and search actions.
3
+ *
4
+ * Each of these actions does the same three things before it does anything
5
+ * interesting: resolve a key, build a client, and turn whatever went wrong into a
6
+ * result object rather than an exception. That lives here so seven actions cannot
7
+ * drift into seven different answers for "no credential configured".
8
+ *
9
+ * {@link CreateClient} is a protected seam purely so tests can substitute a fake
10
+ * client. Nothing in this package may reach api.apollo.io from a test: a live call
11
+ * would spend real credits, and the move surface would mutate a real Apollo
12
+ * account's list membership with no undo.
13
+ */
14
+ import { BaseAction } from '@memberjunction/actions';
15
+ import type { ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
16
+ import type { IApolloRESTClient } from '../generic/apollo-lists.types.js';
17
+ import { type ResolvedApolloKey } from './credentials.js';
18
+ /** A resolved client plus how its key was found. */
19
+ export interface ResolvedApolloClient {
20
+ client: IApolloRESTClient;
21
+ key: ResolvedApolloKey;
22
+ }
23
+ export declare abstract class ApolloRESTBaseAction extends BaseAction {
24
+ /**
25
+ * Build the client. Overridden in tests; the only place `ApolloRESTClient` is
26
+ * constructed in this surface.
27
+ */
28
+ protected CreateClient(apiKey: string): IApolloRESTClient;
29
+ /**
30
+ * Resolve the key and construct the client, or return the failure result to
31
+ * hand straight back to the caller.
32
+ *
33
+ * `CompanyID` is optional here, unlike in the CDP actions this ports from,
34
+ * because a single-tenant instance with `APOLLO_API_KEY` set has no company
35
+ * to name. Supplying it switches on the per-company credential path.
36
+ */
37
+ protected ResolveClient(params: RunActionParams): Promise<{
38
+ resolved: ResolvedApolloClient;
39
+ error: null;
40
+ } | {
41
+ resolved: null;
42
+ error: ActionResultSimple;
43
+ }>;
44
+ /** A uniform missing-input failure. */
45
+ protected MissingField(name: string, detail?: string): ActionResultSimple;
46
+ /** A uniform validation failure. */
47
+ protected Invalid(message: string): ActionResultSimple;
48
+ }
49
+ //# sourceMappingURL=ApolloRESTBaseAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloRESTBaseAction.d.ts","sourceRoot":"","sources":["../../src/lists/ApolloRESTBaseAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E,OAAO,EAA8C,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGtG,oDAAoD;AACpD,MAAM,WAAW,oBAAoB;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,iBAAiB,CAAC;CAC1B;AAED,8BAAsB,oBAAqB,SAAQ,UAAU;IACzD;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB;IAIzD;;;;;;;OAOG;cACa,aAAa,CACzB,MAAM,EAAE,eAAe,GACxB,OAAO,CAAC;QAAE,QAAQ,EAAE,oBAAoB,CAAC;QAAC,KAAK,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,QAAQ,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,kBAAkB,CAAA;KAAE,CAAC;IAuB3G,uCAAuC;IACvC,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,kBAAkB;IAQzE,oCAAoC;IACpC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB;CAGzD"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Shared plumbing for the Apollo list and search actions.
3
+ *
4
+ * Each of these actions does the same three things before it does anything
5
+ * interesting: resolve a key, build a client, and turn whatever went wrong into a
6
+ * result object rather than an exception. That lives here so seven actions cannot
7
+ * drift into seven different answers for "no credential configured".
8
+ *
9
+ * {@link CreateClient} is a protected seam purely so tests can substitute a fake
10
+ * client. Nothing in this package may reach api.apollo.io from a test: a live call
11
+ * would spend real credits, and the move surface would mutate a real Apollo
12
+ * account's list membership with no undo.
13
+ */
14
+ import { BaseAction } from '@memberjunction/actions';
15
+ import { ApolloRESTClient } from './ApolloRESTClient.js';
16
+ import { NO_APOLLO_KEY_MESSAGE, resolveApolloAPIKey } from './credentials.js';
17
+ import { getParam } from './params.js';
18
+ export class ApolloRESTBaseAction extends BaseAction {
19
+ /**
20
+ * Build the client. Overridden in tests; the only place `ApolloRESTClient` is
21
+ * constructed in this surface.
22
+ */
23
+ CreateClient(apiKey) {
24
+ return new ApolloRESTClient(apiKey);
25
+ }
26
+ /**
27
+ * Resolve the key and construct the client, or return the failure result to
28
+ * hand straight back to the caller.
29
+ *
30
+ * `CompanyID` is optional here, unlike in the CDP actions this ports from,
31
+ * because a single-tenant instance with `APOLLO_API_KEY` set has no company
32
+ * to name. Supplying it switches on the per-company credential path.
33
+ */
34
+ async ResolveClient(params) {
35
+ const companyID = getParam(params, 'CompanyID');
36
+ let key;
37
+ try {
38
+ key = await resolveApolloAPIKey(companyID, params.ContextUser);
39
+ }
40
+ catch (error) {
41
+ // A credential that exists but is malformed — say so, rather than
42
+ // falling back to a different workspace's key from the environment.
43
+ return {
44
+ resolved: null,
45
+ error: {
46
+ Success: false,
47
+ Message: error instanceof Error ? error.message : String(error),
48
+ ResultCode: 'CONFIGURATION_ERROR',
49
+ },
50
+ };
51
+ }
52
+ if (!key) {
53
+ return { resolved: null, error: { Success: false, Message: NO_APOLLO_KEY_MESSAGE, ResultCode: 'CREDENTIALS_NOT_FOUND' } };
54
+ }
55
+ return { resolved: { client: this.CreateClient(key.apiKey), key }, error: null };
56
+ }
57
+ /** A uniform missing-input failure. */
58
+ MissingField(name, detail) {
59
+ return {
60
+ Success: false,
61
+ Message: `Missing required field: ${name}${detail ? ` (${detail})` : ''}`,
62
+ ResultCode: 'MISSING_REQUIRED_FIELDS',
63
+ };
64
+ }
65
+ /** A uniform validation failure. */
66
+ Invalid(message) {
67
+ return { Success: false, Message: message, ResultCode: 'VALIDATION_ERROR' };
68
+ }
69
+ }
70
+ //# sourceMappingURL=ApolloRESTBaseAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloRESTBaseAction.js","sourceRoot":"","sources":["../../src/lists/ApolloRESTBaseAction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBA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