@foxtware/mineral 0.1.26 → 0.1.28
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/.creds.yml.sample +22 -4
- package/AGENTS.md +17 -0
- package/api/fastsimon/.gitkeep +0 -0
- package/api/fastsimon/docs.md +14 -0
- package/api/fastsimon/fastsimon.constants.js +18 -0
- package/api/fastsimon/fastsimon.utils.js +246 -0
- package/api/fastsimon/fastsimonSearch.js +84 -0
- package/api/figma/docs.md +3 -3
- package/api/figma/figma.constants.js +1 -1
- package/api/figma/figma.utils.js +13 -2
- package/api/figma/figmaActivityLogsGet.js +44 -0
- package/api/figma/figmaAiUsageDailyGet.js +44 -0
- package/api/figma/figmaComponentGet.js +48 -0
- package/api/figma/figmaComponentSetGet.js +48 -0
- package/api/figma/figmaDevResourcesCreate.js +47 -0
- package/api/figma/figmaDevResourcesUpdate.js +47 -0
- package/api/figma/figmaDeveloperLogsCreate.js +47 -0
- package/api/figma/figmaDiscoveryGet.js +44 -0
- package/api/figma/figmaFileCommentCreate.js +50 -0
- package/api/figma/figmaFileCommentDelete.js +51 -0
- package/api/figma/figmaFileCommentReactionCreate.js +53 -0
- package/api/figma/figmaFileCommentReactionDelete.js +51 -0
- package/api/figma/figmaFileCommentReactionsGet.js +51 -0
- package/api/figma/figmaFileCommentsGet.js +48 -0
- package/api/figma/figmaFileComponentSetsGet.js +48 -0
- package/api/figma/figmaFileComponentsGet.js +48 -0
- package/api/figma/figmaFileDevResourceDelete.js +51 -0
- package/api/figma/figmaFileDevResourcesGet.js +48 -0
- package/api/figma/figmaFileGet.js +48 -0
- package/api/figma/figmaFileImageFillsGet.js +48 -0
- package/api/figma/figmaFileImagesGet.js +48 -0
- package/api/figma/figmaFileMetaGet.js +48 -0
- package/api/figma/figmaFileNodesGet.js +48 -0
- package/api/figma/figmaFileStylesGet.js +48 -0
- package/api/figma/figmaFileVersionsGet.js +48 -0
- package/api/figma/figmaFolderFilesGet.js +48 -0
- package/api/figma/figmaFolderFoldersGet.js +48 -0
- package/api/figma/figmaFolderMetaGet.js +48 -0
- package/api/figma/figmaGet.js +15 -63
- package/api/figma/figmaMeGet.js +53 -0
- package/api/figma/figmaOembedGet.js +44 -0
- package/api/figma/figmaPaymentsGet.js +44 -0
- package/api/figma/figmaProjectFilesGet.js +48 -0
- package/api/figma/figmaProjectMetaGet.js +48 -0
- package/api/figma/figmaStyleGet.js +48 -0
- package/api/figma/figmaTeamComponentSetsGet.js +48 -0
- package/api/figma/figmaTeamComponentsGet.js +48 -0
- package/api/figma/figmaTeamFoldersGet.js +48 -0
- package/api/figma/figmaTeamProjectsGet.js +48 -0
- package/api/figma/figmaTeamStylesGet.js +48 -0
- package/api/figma/figmaTeamWebhooksGet.js +47 -0
- package/api/figma/figmaVariablesLocalGet.js +48 -0
- package/api/figma/figmaVariablesPublishedGet.js +48 -0
- package/api/figma/figmaVariablesUpdate.js +50 -0
- package/api/figma/figmaWebhookCreate.js +47 -0
- package/api/figma/figmaWebhookDelete.js +48 -0
- package/api/figma/figmaWebhookGet.js +46 -0
- package/api/figma/figmaWebhookRequestsGet.js +47 -0
- package/api/figma/figmaWebhookUpdate.js +50 -0
- package/api/figma/figmaWebhooksGet.js +47 -0
- package/api/gorgias/gorgiasTicketCreate.js +1 -1
- package/api/gorgias/gorgiasTicketMessageCreate.js +1 -1
- package/api/gorgias/gorgiasTicketUpdate.js +1 -1
- package/api/linear/linearAttachmentCreate.js +1 -1
- package/api/linear/linearCommentCreate.js +1 -1
- package/api/linear/linearCommentUpdate.js +1 -1
- package/api/linear/linearIssueLabelCreate.js +1 -1
- package/api/linear/linearIssueUpdate.js +1 -1
- package/api/linear/linearProjectCreate.js +1 -1
- package/api/linear/linearProjectUpdate.js +1 -1
- package/api/linear/linearWebhookCreate.js +1 -1
- package/api/salesforce/salesforce.constants.js +13 -0
- package/api/salesforce/salesforce.utils.js +61 -0
- package/api/salesforce/salesforceAuthGet.js +115 -0
- package/api/salesforce/salesforceComposite.js +79 -0
- package/api/salesforce/salesforceCompositeBatch.js +73 -0
- package/api/salesforce/salesforceLimitsGet.js +55 -0
- package/api/salesforce/salesforceQuery.js +69 -0
- package/api/salesforce/salesforceQueryAll.js +62 -0
- package/api/salesforce/salesforceQueryMore.js +75 -0
- package/api/salesforce/salesforceRecentItemsGet.js +63 -0
- package/api/salesforce/salesforceResourcesGet.js +55 -0
- package/api/salesforce/salesforceSearch.js +62 -0
- package/api/salesforce/salesforceSobjectBasicInfoGet.js +81 -0
- package/api/salesforce/salesforceSobjectBlobGet.js +67 -0
- package/api/salesforce/salesforceSobjectCollectionCreate.js +78 -0
- package/api/salesforce/salesforceSobjectCollectionDelete.js +70 -0
- package/api/salesforce/salesforceSobjectCollectionGet.js +75 -0
- package/api/salesforce/salesforceSobjectCollectionUpdate.js +74 -0
- package/api/salesforce/salesforceSobjectCreate.js +66 -0
- package/api/salesforce/salesforceSobjectDelete.js +86 -0
- package/api/salesforce/salesforceSobjectDeleteByExternalId.js +91 -0
- package/api/salesforce/salesforceSobjectDeletedGet.js +71 -0
- package/api/salesforce/salesforceSobjectDescribe.js +81 -0
- package/api/salesforce/salesforceSobjectDescribeLayouts.js +64 -0
- package/api/salesforce/salesforceSobjectGet.js +93 -0
- package/api/salesforce/salesforceSobjectGetByExternalId.js +98 -0
- package/api/salesforce/salesforceSobjectTreeCreate.js +79 -0
- package/api/salesforce/salesforceSobjectUpdate.js +94 -0
- package/api/salesforce/salesforceSobjectUpdatedGet.js +71 -0
- package/api/salesforce/salesforceSobjectUpsert.js +74 -0
- package/api/salesforce/salesforceSobjectsDescribeGlobal.js +55 -0
- package/api/salesforce/salesforceVersionsGet.js +62 -0
- package/api/shopify/shopifyMetaobjectCreate.js +72 -0
- package/api/tableau/tableau.constants.js +8 -0
- package/api/tableau/tableau.utils.js +93 -0
- package/api/tableau/tableauGet.js +174 -0
- package/api/tableau/tableauUserAdd.js +16 -94
- package/api/tableau/tableauUsersGet.js +46 -134
- package/api/tagalys/docs.md +2 -2
- package/api/tagalys/tagalys.constants.js +17 -0
- package/api/tagalys/tagalys.utils.js +125 -0
- package/api/tagalys/tagalysAnalyticsEventSend.js +125 -0
- package/api/tagalys/tagalysCollectionGet.js +100 -0
- package/api/tagalys/tagalysPopularSearchesGet.js +60 -0
- package/api/tagalys/tagalysRecommendationGet.js +109 -0
- package/api/tagalys/tagalysSearch.js +82 -0
- package/api/tagalys/tagalysSearchSuggestionsGet.js +76 -0
- package/package.json +2 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const { DEFAULT_API_VERSION } = require('../tableau/tableau.constants');
|
|
2
|
+
const { resolveCreds } = require('../pipelineSteps');
|
|
3
|
+
const {
|
|
4
|
+
FetchClient,
|
|
5
|
+
appendUrlToBase,
|
|
6
|
+
fetchClientCommonSteps,
|
|
7
|
+
} = require('../utils');
|
|
8
|
+
|
|
9
|
+
// Tableau sessions are token-based (sign in -> token, valid ~2hrs by default
|
|
10
|
+
// server config), unlike Shopify's static API key. We cache tokens per
|
|
11
|
+
// server+site so we're not re-signing-in on every single call.
|
|
12
|
+
const tokenCache = new Map();
|
|
13
|
+
|
|
14
|
+
const tableauSignIn = async ({
|
|
15
|
+
SERVER_URL,
|
|
16
|
+
PAT_NAME,
|
|
17
|
+
PAT_SECRET,
|
|
18
|
+
SITE_CONTENT_URL = '',
|
|
19
|
+
}) => {
|
|
20
|
+
const cacheKey = `${ SERVER_URL }::${ SITE_CONTENT_URL }`;
|
|
21
|
+
const cached = tokenCache.get(cacheKey);
|
|
22
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
23
|
+
return cached;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const response = await fetch(`${ SERVER_URL }/api/${ DEFAULT_API_VERSION }/auth/signin`, {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
Accept: 'application/json',
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
credentials: {
|
|
34
|
+
personalAccessTokenName: PAT_NAME,
|
|
35
|
+
personalAccessTokenSecret: PAT_SECRET,
|
|
36
|
+
site: { contentUrl: SITE_CONTENT_URL },
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
throw new Error(`Tableau sign-in failed: ${ response.status } ${ await response.text() }`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { credentials } = await response.json();
|
|
46
|
+
|
|
47
|
+
const session = {
|
|
48
|
+
token: credentials.token,
|
|
49
|
+
siteId: credentials.site.id,
|
|
50
|
+
// Refresh a bit early rather than riding right up against the server's
|
|
51
|
+
// idle/absolute timeout.
|
|
52
|
+
expiresAt: Date.now() + 1000 * 60 * 60 * 2,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
tokenCache.set(cacheKey, session);
|
|
56
|
+
return session;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const useUrlAndAuthHeaders = async (state) => {
|
|
60
|
+
const { requestPayload, context } = state;
|
|
61
|
+
const { creds } = context;
|
|
62
|
+
|
|
63
|
+
const { token, siteId } = await tableauSignIn(creds);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
requestPayload: {
|
|
67
|
+
...requestPayload,
|
|
68
|
+
url: appendUrlToBase(
|
|
69
|
+
`${ creds.SERVER_URL }/api/${ DEFAULT_API_VERSION }`,
|
|
70
|
+
requestPayload.url.replace('{siteId}', siteId),
|
|
71
|
+
),
|
|
72
|
+
headers: {
|
|
73
|
+
'X-Tableau-Auth': token,
|
|
74
|
+
Accept: 'application/json',
|
|
75
|
+
...requestPayload.headers,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const tableauClient = new FetchClient({
|
|
82
|
+
pipeline: [
|
|
83
|
+
resolveCreds,
|
|
84
|
+
useUrlAndAuthHeaders,
|
|
85
|
+
'fetch',
|
|
86
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
tableauClient,
|
|
92
|
+
tableauSignIn,
|
|
93
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_paging.htm
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, Getter } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { tableauClient } = require('../tableau/tableau.utils');
|
|
6
|
+
const { MAX_PER_PAGE } = require('../tableau/tableau.constants');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
['url'],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
// Tableau list responses nest items, e.g. data.users.user, data.workbooks.workbook.
|
|
14
|
+
// resultsKey may be a dotted path such as "users.user".
|
|
15
|
+
const digResults = (data, resultsKey) => {
|
|
16
|
+
if (resultsKey) {
|
|
17
|
+
const value = resultsKey.split('.').reduce(
|
|
18
|
+
(node, key) => node?.[key],
|
|
19
|
+
data,
|
|
20
|
+
);
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
return value != null ? [value] : [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (Array.isArray(data)) {
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const arrayEntry = Object.entries(data || {}).find(([, value]) => Array.isArray(value));
|
|
32
|
+
return arrayEntry ? arrayEntry[1] : [];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const tableauGetPacket = async (
|
|
36
|
+
credsPayload,
|
|
37
|
+
url,
|
|
38
|
+
{
|
|
39
|
+
params,
|
|
40
|
+
perPage = MAX_PER_PAGE,
|
|
41
|
+
fetchClient = tableauClient,
|
|
42
|
+
} = {},
|
|
43
|
+
) => {
|
|
44
|
+
return fetchClient.fetch({
|
|
45
|
+
requestPayload: {
|
|
46
|
+
method: 'get',
|
|
47
|
+
url,
|
|
48
|
+
params: {
|
|
49
|
+
pageSize: Math.min(perPage, MAX_PER_PAGE),
|
|
50
|
+
pageNumber: 1,
|
|
51
|
+
...params,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
context: {
|
|
55
|
+
credsPayload,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const tableauGetPaginator = async (currentParams, response) => {
|
|
61
|
+
if (!response?.ok) {
|
|
62
|
+
return [true];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const pagination = response?.data?.pagination;
|
|
66
|
+
if (!pagination) {
|
|
67
|
+
return [true];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const pageNumber = Number(pagination.pageNumber);
|
|
71
|
+
const pageSize = Number(pagination.pageSize);
|
|
72
|
+
const totalAvailable = Number(pagination.totalAvailable);
|
|
73
|
+
|
|
74
|
+
if (!pageNumber || !pageSize || Number.isNaN(totalAvailable)) {
|
|
75
|
+
return [true];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (pageNumber * pageSize >= totalAvailable) {
|
|
79
|
+
return [true];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { args, options } = currentParams;
|
|
83
|
+
|
|
84
|
+
return [false, {
|
|
85
|
+
args,
|
|
86
|
+
options: {
|
|
87
|
+
...options,
|
|
88
|
+
params: {
|
|
89
|
+
...options.params,
|
|
90
|
+
pageNumber: pageNumber + 1,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
}];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const tableauGet = async (
|
|
97
|
+
returnGetter,
|
|
98
|
+
|
|
99
|
+
credsPayload,
|
|
100
|
+
url,
|
|
101
|
+
{
|
|
102
|
+
params,
|
|
103
|
+
perPage = MAX_PER_PAGE,
|
|
104
|
+
resultsKey,
|
|
105
|
+
fetchClient,
|
|
106
|
+
...getterOptions
|
|
107
|
+
} = {},
|
|
108
|
+
) => {
|
|
109
|
+
|
|
110
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
111
|
+
credsPayload,
|
|
112
|
+
url,
|
|
113
|
+
});
|
|
114
|
+
if (rejectResponse) {
|
|
115
|
+
return rejectResponse;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const getter = new Getter(
|
|
119
|
+
{
|
|
120
|
+
args: [credsPayload, url],
|
|
121
|
+
options: {
|
|
122
|
+
params,
|
|
123
|
+
perPage,
|
|
124
|
+
fetchClient,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
func: tableauGetPacket,
|
|
129
|
+
digester: (response) => {
|
|
130
|
+
if (!response?.ok) {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return digResults(response.data, resultsKey);
|
|
135
|
+
},
|
|
136
|
+
paginator: tableauGetPaginator,
|
|
137
|
+
...getterOptions,
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (returnGetter) {
|
|
142
|
+
return getter;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const data = await getter.run({ returnAll: true });
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
ok: true,
|
|
149
|
+
data,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const funcApiConfig = {
|
|
154
|
+
argsWarden,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
module.exports = {
|
|
158
|
+
tableauGet: (...args) => tableauGet(false, ...args),
|
|
159
|
+
tableauGetter: (...args) => tableauGet(true, ...args),
|
|
160
|
+
funcApiConfig,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
curl -X POST "http://localhost:8000/tableauGet" \
|
|
165
|
+
-H "Content-Type: application/json" \
|
|
166
|
+
-d '{
|
|
167
|
+
"credsPayload": { "credsPath": "tableau" },
|
|
168
|
+
"url": "/sites/{siteId}/users",
|
|
169
|
+
"options": {
|
|
170
|
+
"resultsKey": "users.user",
|
|
171
|
+
"perPage": 100
|
|
172
|
+
}
|
|
173
|
+
}'
|
|
174
|
+
*/
|
|
@@ -1,96 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
const { resolveCreds } = require('../pipelineSteps');
|
|
3
|
-
const {
|
|
4
|
-
FetchClient,
|
|
5
|
-
appendUrlToBase,
|
|
6
|
-
fetchClientCommonSteps,
|
|
7
|
-
} = require('../utils');
|
|
8
|
-
|
|
9
|
-
const DEFAULT_API_VERSION = '3.22';
|
|
10
|
-
|
|
11
|
-
// Tableau sessions are token-based (sign in -> token, valid ~2hrs by default
|
|
12
|
-
// server config), unlike Shopify's static API key. We cache tokens per
|
|
13
|
-
// server+site so we're not re-signing-in on every single call.
|
|
14
|
-
const tokenCache = new Map();
|
|
15
|
-
|
|
16
|
-
const tableauSignIn = async ({
|
|
17
|
-
SERVER_URL,
|
|
18
|
-
PAT_NAME,
|
|
19
|
-
PAT_SECRET,
|
|
20
|
-
SITE_CONTENT_URL = '',
|
|
21
|
-
}) => {
|
|
22
|
-
const cacheKey = `${ SERVER_URL }::${ SITE_CONTENT_URL }`;
|
|
23
|
-
const cached = tokenCache.get(cacheKey);
|
|
24
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
25
|
-
return cached;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const response = await fetch(`${ SERVER_URL }/api/${ DEFAULT_API_VERSION }/auth/signin`, {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
headers: {
|
|
31
|
-
'Content-Type': 'application/json',
|
|
32
|
-
Accept: 'application/json',
|
|
33
|
-
},
|
|
34
|
-
body: JSON.stringify({
|
|
35
|
-
credentials: {
|
|
36
|
-
personalAccessTokenName: PAT_NAME,
|
|
37
|
-
personalAccessTokenSecret: PAT_SECRET,
|
|
38
|
-
site: { contentUrl: SITE_CONTENT_URL },
|
|
39
|
-
},
|
|
40
|
-
}),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (!response.ok) {
|
|
44
|
-
throw new Error(`Tableau sign-in failed: ${ response.status } ${ await response.text() }`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const { credentials } = await response.json();
|
|
48
|
-
|
|
49
|
-
const session = {
|
|
50
|
-
token: credentials.token,
|
|
51
|
-
siteId: credentials.site.id,
|
|
52
|
-
// Refresh a bit early rather than riding right up against the server's
|
|
53
|
-
// idle/absolute timeout.
|
|
54
|
-
expiresAt: Date.now() + 1000 * 60 * 60 * 2,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
tokenCache.set(cacheKey, session);
|
|
58
|
-
return session;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const useUrlAndAuthHeaders = async (state) => {
|
|
62
|
-
const { requestPayload, context } = state;
|
|
63
|
-
const { creds } = context;
|
|
1
|
+
// https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_users_and_groups.htm#add_user_to_site
|
|
64
2
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
requestPayload: {
|
|
69
|
-
...requestPayload,
|
|
70
|
-
url: appendUrlToBase(
|
|
71
|
-
`${ creds.SERVER_URL }/api/${ DEFAULT_API_VERSION }`,
|
|
72
|
-
requestPayload.url.replace('{siteId}', siteId),
|
|
73
|
-
),
|
|
74
|
-
headers: {
|
|
75
|
-
'X-Tableau-Auth': token,
|
|
76
|
-
'Content-Type': 'application/json',
|
|
77
|
-
Accept: 'application/json',
|
|
78
|
-
...requestPayload.headers,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const tableauClient = new FetchClient({
|
|
85
|
-
pipeline: [
|
|
86
|
-
resolveCreds,
|
|
87
|
-
useUrlAndAuthHeaders,
|
|
88
|
-
'fetch',
|
|
89
|
-
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
90
|
-
],
|
|
91
|
-
});
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { tableauClient } = require('../tableau/tableau.utils');
|
|
92
6
|
|
|
93
7
|
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
94
9
|
['username'],
|
|
95
10
|
['siteRole'],
|
|
96
11
|
]);
|
|
@@ -99,13 +14,16 @@ const argsWarden = new ArgsWarden([
|
|
|
99
14
|
// role: Creator, Explorer, ExplorerCanPublish, Viewer, SiteAdministratorCreator,
|
|
100
15
|
// SiteAdministratorExplorer, Unlicensed, etc.
|
|
101
16
|
const tableauUserAdd = async (
|
|
17
|
+
credsPayload,
|
|
102
18
|
username,
|
|
103
19
|
siteRole = 'Viewer',
|
|
104
20
|
{
|
|
105
21
|
authSetting, // optional: 'ServerDefault' | 'SAML' | 'OpenID' | 'TableauIDWithMFA' ...
|
|
22
|
+
fetchClient = tableauClient,
|
|
106
23
|
} = {},
|
|
107
24
|
) => {
|
|
108
25
|
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
26
|
+
credsPayload,
|
|
109
27
|
username,
|
|
110
28
|
siteRole,
|
|
111
29
|
});
|
|
@@ -113,9 +31,9 @@ const tableauUserAdd = async (
|
|
|
113
31
|
return rejectResponse;
|
|
114
32
|
}
|
|
115
33
|
|
|
116
|
-
const response = await
|
|
34
|
+
const response = await fetchClient.fetch({
|
|
117
35
|
context: {
|
|
118
|
-
credsPayload
|
|
36
|
+
credsPayload,
|
|
119
37
|
},
|
|
120
38
|
requestPayload: {
|
|
121
39
|
url: '/sites/{siteId}/users',
|
|
@@ -148,11 +66,15 @@ const funcApiConfig = {
|
|
|
148
66
|
|
|
149
67
|
module.exports = {
|
|
150
68
|
tableauUserAdd,
|
|
151
|
-
tableauClient,
|
|
152
69
|
funcApiConfig,
|
|
153
70
|
};
|
|
154
71
|
|
|
155
72
|
/*
|
|
156
73
|
curl -X POST "http://localhost:8000/tableauUserAdd" \
|
|
157
|
-
-
|
|
74
|
+
-H "Content-Type: application/json" \
|
|
75
|
+
-d '{
|
|
76
|
+
"credsPayload": { "credsPath": "tableau" },
|
|
77
|
+
"username": "dora@example.com",
|
|
78
|
+
"siteRole": "Explorer"
|
|
79
|
+
}'
|
|
158
80
|
*/
|
|
@@ -1,155 +1,67 @@
|
|
|
1
|
+
// https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_users_and_groups.htm#query_users_on_site
|
|
1
2
|
// GET /api/{api-version}/sites/{site-id}/users is paginated (default pageSize
|
|
2
3
|
// is 100, max 1000), so this walks all pages and returns the full list.
|
|
3
4
|
|
|
4
|
-
const { ArgsWarden
|
|
5
|
-
const {
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
appendUrlToBase,
|
|
9
|
-
fetchClientCommonSteps,
|
|
10
|
-
} = require('../utils');
|
|
5
|
+
const { ArgsWarden } = require('../utils');
|
|
6
|
+
const { credsValidator } = require('../validators');
|
|
7
|
+
const { tableauGet } = require('../tableau/tableauGet');
|
|
8
|
+
const { MAX_PER_PAGE } = require('../tableau/tableau.constants');
|
|
11
9
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const tokenCache = new Map();
|
|
16
|
-
|
|
17
|
-
const tableauSignIn = async ({
|
|
18
|
-
SERVER_URL,
|
|
19
|
-
PAT_NAME,
|
|
20
|
-
PAT_SECRET,
|
|
21
|
-
SITE_CONTENT_URL = '',
|
|
22
|
-
}) => {
|
|
23
|
-
const cacheKey = `${ SERVER_URL }::${ SITE_CONTENT_URL }`;
|
|
24
|
-
const cached = tokenCache.get(cacheKey);
|
|
25
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
26
|
-
return cached;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const response = await fetch(`${ SERVER_URL }/api/${ DEFAULT_API_VERSION }/auth/signin`, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
Accept: 'application/json',
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify({
|
|
36
|
-
credentials: {
|
|
37
|
-
personalAccessTokenName: PAT_NAME,
|
|
38
|
-
personalAccessTokenSecret: PAT_SECRET,
|
|
39
|
-
site: { contentUrl: SITE_CONTENT_URL },
|
|
40
|
-
},
|
|
41
|
-
}),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
throw new Error(`Tableau sign-in failed: ${ response.status } ${ await response.text() }`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const { credentials } = await response.json();
|
|
49
|
-
|
|
50
|
-
const session = {
|
|
51
|
-
token: credentials.token,
|
|
52
|
-
siteId: credentials.site.id,
|
|
53
|
-
expiresAt: Date.now() + 1000 * 60 * 60 * 2,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
tokenCache.set(cacheKey, session);
|
|
57
|
-
return session;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const useUrlAndAuthHeaders = async (state) => {
|
|
61
|
-
const { requestPayload, context } = state;
|
|
62
|
-
const { creds } = context;
|
|
63
|
-
|
|
64
|
-
const { token, siteId } = await tableauSignIn(creds);
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
requestPayload: {
|
|
68
|
-
...requestPayload,
|
|
69
|
-
url: appendUrlToBase(
|
|
70
|
-
`${ creds.SERVER_URL }/api/${ DEFAULT_API_VERSION }`,
|
|
71
|
-
requestPayload.url.replace('{siteId}', siteId),
|
|
72
|
-
),
|
|
73
|
-
headers: {
|
|
74
|
-
'X-Tableau-Auth': token,
|
|
75
|
-
'Content-Type': 'application/json',
|
|
76
|
-
Accept: 'application/json',
|
|
77
|
-
...requestPayload.headers,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const tableauClient = new FetchClient({
|
|
84
|
-
pipeline: [
|
|
85
|
-
resolveCreds,
|
|
86
|
-
useUrlAndAuthHeaders,
|
|
87
|
-
'fetch',
|
|
88
|
-
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
89
|
-
],
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const argsWarden = new ArgsWarden([]);
|
|
10
|
+
const argsWarden = new ArgsWarden([
|
|
11
|
+
['credsPayload', credsValidator],
|
|
12
|
+
]);
|
|
93
13
|
|
|
94
14
|
// Optional filter, e.g. { filter: "siteRole:eq:Explorer" } or
|
|
95
15
|
// { filter: "name:has:jane" } per Tableau's filter-expression syntax.
|
|
96
|
-
const tableauUsersGet = async (
|
|
97
|
-
|
|
16
|
+
const tableauUsersGet = async (
|
|
17
|
+
credsPayload,
|
|
18
|
+
{
|
|
19
|
+
filter,
|
|
20
|
+
perPage = MAX_PER_PAGE,
|
|
21
|
+
fetchClient,
|
|
22
|
+
...getterOptions
|
|
23
|
+
} = {},
|
|
24
|
+
) => {
|
|
25
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
26
|
+
credsPayload,
|
|
27
|
+
});
|
|
98
28
|
if (rejectResponse) {
|
|
99
29
|
return rejectResponse;
|
|
100
30
|
}
|
|
101
31
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
while (true) {
|
|
106
|
-
const query = new URLSearchParams({
|
|
107
|
-
pageSize: String(PAGE_SIZE),
|
|
108
|
-
pageNumber: String(pageNumber),
|
|
32
|
+
return tableauGet(credsPayload, '/sites/{siteId}/users', {
|
|
33
|
+
params: {
|
|
109
34
|
...(filter ? { filter } : {}),
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
url: `/sites/{siteId}/users?${ query.toString() }`,
|
|
118
|
-
method: 'get',
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const { ok, data, error } = response;
|
|
123
|
-
if (!ok) {
|
|
124
|
-
logDeep({ error });
|
|
125
|
-
return { ok: false, error };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const pageUsers = data?.users?.user ?? [];
|
|
129
|
-
users.push(...pageUsers);
|
|
130
|
-
|
|
131
|
-
const totalAvailable = Number(data?.pagination?.totalAvailable ?? pageUsers.length);
|
|
132
|
-
if (users.length >= totalAvailable || pageUsers.length === 0) {
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
pageNumber += 1;
|
|
137
|
-
}
|
|
35
|
+
},
|
|
36
|
+
perPage,
|
|
37
|
+
resultsKey: 'users.user',
|
|
38
|
+
fetchClient,
|
|
39
|
+
...getterOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
138
42
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
data: users,
|
|
142
|
-
};
|
|
43
|
+
const funcApiConfig = {
|
|
44
|
+
argsWarden,
|
|
143
45
|
};
|
|
144
46
|
|
|
145
47
|
module.exports = {
|
|
146
48
|
tableauUsersGet,
|
|
147
|
-
|
|
49
|
+
funcApiConfig,
|
|
148
50
|
};
|
|
149
51
|
|
|
150
52
|
/*
|
|
151
|
-
curl -X POST "http://localhost:8000/tableauUsersGet"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
53
|
+
curl -X POST "http://localhost:8000/tableauUsersGet" \
|
|
54
|
+
-H "Content-Type: application/json" \
|
|
55
|
+
-d '{
|
|
56
|
+
"credsPayload": { "credsPath": "tableau" }
|
|
57
|
+
}'
|
|
58
|
+
|
|
59
|
+
curl -X POST "http://localhost:8000/tableauUsersGet" \
|
|
60
|
+
-H "Content-Type: application/json" \
|
|
61
|
+
-d '{
|
|
62
|
+
"credsPayload": { "credsPath": "tableau" },
|
|
63
|
+
"options": {
|
|
64
|
+
"filter": "siteRole:eq:Creator"
|
|
65
|
+
}
|
|
66
|
+
}'
|
|
155
67
|
*/
|
package/api/tagalys/docs.md
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
- [Storefront API (v2)](https://tagalys.notion.site/Storefront-API-v2-20eacdd38c2080d58d3fd0cf6f24e435)
|
|
4
4
|
|
|
5
|
-
Region-specific HTTPS origins (`https://api-r{n}.tagalys.com`) with REST-style JSON under `/v2`. Storefront reads use GET; analytics ingest uses `POST /v2/analytics/events` with a JSON body. Browser requests authenticate with the `shop_id` query param (the shop
|
|
5
|
+
Region-specific HTTPS origins (`https://api-r{n}.tagalys.com`) with REST-style JSON under `/v2`. Storefront reads use GET; analytics ingest uses `POST /v2/analytics/events` with a JSON body. Browser requests authenticate with the `shop_id` query param (the shop's `*.myshopify.com` domain). Server-side integrations should also pass an API key -- the published docs name this param `storefront_api_key`, but live testing against this account found `api_key` is what actually authenticates (see tagalys.utils.js).
|
|
6
6
|
|
|
7
|
-
Endpoints: `GET /v2/collections/:collection_id`, `GET /v2/search`, `GET /v2/search_suggestions`, `GET /v2/popular_searches`, `GET /v2/recommendations/:recommendation_id`, `POST /v2/analytics/events`. Collections and search support pagination (`page`, `per_page`, capped at 10,000 products), sorting (`sort`, `include[]=sort_options`), filtering (`filter[...]`, `include[]=filters`), and scope (`scope[...]
|
|
7
|
+
Endpoints: `GET /v2/collections/:collection_id`, `GET /v2/search`, `GET /v2/search_suggestions`, `GET /v2/popular_searches`, `GET /v2/recommendations/:recommendation_id`, `POST /v2/analytics/events`. Collections and search support pagination (`page`, `per_page`, capped at 10,000 products), sorting (`sort`, `include[]=sort_options`), filtering (`filter[...]`, `include[]=filters`), and scope (`scope[...]`, a fixed server-side constraint rather than a shopper-facing facet). Collections also support `banner_positions` to reduce returned products around merchandising banners. Use `include[]=products` or `include[]=product_ids` to control product payloads. Optional request context on collections, search, and recommendations: `country`, `language`, `segment_tag`. Search and search_suggestions can return a top-level `redirect_url` for merchant-configured query redirects, which takes precedence over the rest of the response. Errors return JSON with `error.type`, `error.code`, and `error.message`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const DEFAULT_INCLUDE = ['products', 'total_count'];
|
|
2
|
+
|
|
3
|
+
// "Pagination is restricted to the top 10,000 products."
|
|
4
|
+
const MAX_PAGINATION_PRODUCTS = 10000;
|
|
5
|
+
|
|
6
|
+
// "up to 3 are supported" (recommendations :product_ids param)
|
|
7
|
+
const MAX_RECOMMENDATION_PRODUCT_IDS = 3;
|
|
8
|
+
|
|
9
|
+
// "Returns at most 10 queries" (GET /v2/popular_searches)
|
|
10
|
+
const MAX_POPULAR_SEARCHES = 10;
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
DEFAULT_INCLUDE,
|
|
14
|
+
MAX_PAGINATION_PRODUCTS,
|
|
15
|
+
MAX_RECOMMENDATION_PRODUCT_IDS,
|
|
16
|
+
MAX_POPULAR_SEARCHES,
|
|
17
|
+
};
|