@foxtware/mineral 0.1.27 → 0.1.29
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 +29 -0
- package/AGENTS.md +24 -0
- package/_build_scripts/createNewFunction.js +26 -3
- package/api/dropbox/docs.md +7 -0
- package/api/dropbox/dropbox.constants.js +10 -0
- package/api/dropbox/dropbox.utils.js +67 -0
- package/api/dropbox/dropboxAccountGet.js +64 -0
- package/api/dropbox/dropboxFileCopy.js +67 -0
- package/api/dropbox/dropboxFileDelete.js +89 -0
- package/api/dropbox/dropboxFileDownload.js +139 -0
- package/api/dropbox/dropboxFileMetadataGet.js +100 -0
- package/api/dropbox/dropboxFileMove.js +67 -0
- package/api/dropbox/dropboxFileUpload.js +129 -0
- package/api/dropbox/dropboxFolderCreate.js +68 -0
- package/api/dropbox/dropboxFolderList.js +66 -0
- package/api/dropbox/dropboxGet.js +158 -0
- package/api/dropbox/dropboxSearch.js +161 -0
- package/api/dropbox/dropboxSharedLinkCreate.js +68 -0
- package/api/dropbox/dropboxSpaceUsageGet.js +55 -0
- package/api/dropbox/dropboxTemporaryLinkGet.js +75 -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/google/docs.md +1 -0
- package/api/google/google.constants.js +1 -0
- package/api/google/google.utils.js +21 -0
- package/api/google/googleanalyticsMetadataGet.js +62 -0
- package/api/google/googleanalyticsRealtimeReportRun.js +103 -0
- package/api/google/googleanalyticsReportRun.js +114 -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/shopify.utils.js +53 -4
- package/api/shopify/shopifyMetaobjectCreate.js +79 -0
- package/api/shopify/shopifyMetaobjectDelete.js +90 -0
- package/api/shopify/shopifyMetaobjectGet.js +80 -0
- package/api/shopify/shopifyMetaobjectUpdate.js +108 -0
- package/api/shopify/shopifyStorefrontSearch.js +158 -0
- package/api/spotify/docs.md +8 -0
- package/api/spotify/spotify.constants.js +12 -0
- package/api/spotify/spotify.utils.js +106 -0
- package/api/spotify/spotifyAlbumGet.js +76 -0
- package/api/spotify/spotifyAlbumTracksGet.js +49 -0
- package/api/spotify/spotifyArtistAlbumsGet.js +55 -0
- package/api/spotify/spotifyArtistGet.js +71 -0
- package/api/spotify/spotifyArtistTopTracksGet.js +56 -0
- package/api/spotify/spotifyGet.js +171 -0
- package/api/spotify/spotifyMeGet.js +48 -0
- package/api/spotify/spotifyPlayerCurrentlyPlayingGet.js +62 -0
- package/api/spotify/spotifyPlayerDevicesGet.js +51 -0
- package/api/spotify/spotifyPlayerGet.js +63 -0
- package/api/spotify/spotifyPlayerNext.js +55 -0
- package/api/spotify/spotifyPlayerPause.js +55 -0
- package/api/spotify/spotifyPlayerPlay.js +70 -0
- package/api/spotify/spotifyPlayerPrevious.js +55 -0
- package/api/spotify/spotifyPlaylistCreate.js +63 -0
- package/api/spotify/spotifyPlaylistGet.js +91 -0
- package/api/spotify/spotifyPlaylistItemsAdd.js +61 -0
- package/api/spotify/spotifyPlaylistItemsGet.js +58 -0
- package/api/spotify/spotifyPlaylistItemsRemove.js +67 -0
- package/api/spotify/spotifyPlaylistUpdate.js +64 -0
- package/api/spotify/spotifyPlaylistsGet.js +47 -0
- package/api/spotify/spotifySavedTracksGet.js +46 -0
- package/api/spotify/spotifySavedTracksRemove.js +59 -0
- package/api/spotify/spotifySavedTracksSave.js +59 -0
- package/api/spotify/spotifySearch.js +174 -0
- package/api/spotify/spotifyTrackGet.js +76 -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 +15 -89
- package/api/tagalys/tagalysSearchSuggestionsGet.js +76 -0
- package/package.json +2 -1
- package/server.js +3 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// https://tagalys.notion.site/Storefront-API-v2-20eacdd38c2080d58d3fd0cf6f24e435
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden, actionSingleOrMultiple, ensureArray, logDeep } = require('../utils');
|
|
5
|
+
const { MAX_RECOMMENDATION_PRODUCT_IDS } = require('../tagalys/tagalys.constants');
|
|
6
|
+
const { tagalysClient } = require('../tagalys/tagalys.utils');
|
|
7
|
+
|
|
8
|
+
// System-defined ids: bought_also_bought, viewed_also_viewed, atc_also_atc,
|
|
9
|
+
// recently_viewed, personalized. Custom recommendations use a dashboard slug
|
|
10
|
+
// (e.g. 8d72jc02jd719ddc6hw0).
|
|
11
|
+
const argsWarden = new ArgsWarden([
|
|
12
|
+
['credsPayload', credsValidator],
|
|
13
|
+
['recommendationId'],
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const tagalysRecommendationGetSingle = async (
|
|
17
|
+
credsPayload,
|
|
18
|
+
recommendationId,
|
|
19
|
+
{
|
|
20
|
+
productIds, // up to 3, for product-contextual recommendations
|
|
21
|
+
count,
|
|
22
|
+
|
|
23
|
+
// personalized / recently_viewed: either deviceId or userId is required
|
|
24
|
+
deviceId,
|
|
25
|
+
userId,
|
|
26
|
+
|
|
27
|
+
fallbackRecommendationId, // personalized only
|
|
28
|
+
visitId, // recently_viewed only
|
|
29
|
+
|
|
30
|
+
country,
|
|
31
|
+
language,
|
|
32
|
+
segmentTag,
|
|
33
|
+
} = {},
|
|
34
|
+
) => {
|
|
35
|
+
const response = await tagalysClient.fetch({
|
|
36
|
+
context: {
|
|
37
|
+
credsPayload,
|
|
38
|
+
country,
|
|
39
|
+
language,
|
|
40
|
+
segmentTag,
|
|
41
|
+
},
|
|
42
|
+
requestPayload: {
|
|
43
|
+
url: `/v2/recommendations/${ recommendationId }`,
|
|
44
|
+
method: 'get',
|
|
45
|
+
query: {
|
|
46
|
+
...(productIds ? { product_ids: ensureArray(productIds).slice(0, MAX_RECOMMENDATION_PRODUCT_IDS) } : {}),
|
|
47
|
+
...(count ? { count } : {}),
|
|
48
|
+
...(deviceId ? { device_id: deviceId } : {}),
|
|
49
|
+
...(userId ? { user_id: userId } : {}),
|
|
50
|
+
...(fallbackRecommendationId ? { fallback_recommendation_id: fallbackRecommendationId } : {}),
|
|
51
|
+
...(visitId ? { visit_id: visitId } : {}),
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const { ok, error } = response;
|
|
57
|
+
if (!ok) {
|
|
58
|
+
logDeep({ error });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return response;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const tagalysRecommendationGet = async (
|
|
65
|
+
credsPayload,
|
|
66
|
+
recommendationId,
|
|
67
|
+
{
|
|
68
|
+
queueRunOptions,
|
|
69
|
+
...options
|
|
70
|
+
} = {},
|
|
71
|
+
) => {
|
|
72
|
+
|
|
73
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
74
|
+
credsPayload,
|
|
75
|
+
recommendationId,
|
|
76
|
+
});
|
|
77
|
+
if (rejectResponse) {
|
|
78
|
+
return rejectResponse;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return actionSingleOrMultiple(
|
|
82
|
+
recommendationId,
|
|
83
|
+
tagalysRecommendationGetSingle,
|
|
84
|
+
(recommendationIdItem) => ({
|
|
85
|
+
args: [credsPayload, recommendationIdItem, options],
|
|
86
|
+
}),
|
|
87
|
+
{
|
|
88
|
+
...(queueRunOptions ? { queueRunOptions } : {}),
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const funcApiConfig = {
|
|
94
|
+
argsWarden,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
module.exports = {
|
|
98
|
+
tagalysRecommendationGet,
|
|
99
|
+
funcApiConfig,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
curl -X POST "http://localhost:8000/tagalysRecommendationGet" \
|
|
104
|
+
-d '{
|
|
105
|
+
"credsPayload": { "credsPath": "tagalys.au" },
|
|
106
|
+
"recommendationId": "bought_also_bought",
|
|
107
|
+
"options": { "productIds": ["1234567890"], "count": 10 }
|
|
108
|
+
}'
|
|
109
|
+
*/
|
|
@@ -2,84 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const { credsValidator } = require('../validators');
|
|
4
4
|
const { ArgsWarden, logDeep } = require('../utils');
|
|
5
|
-
const {
|
|
6
|
-
const {
|
|
7
|
-
FetchClient,
|
|
8
|
-
fetchClientCommonSteps,
|
|
9
|
-
} = require('../utils');
|
|
10
|
-
|
|
11
|
-
// NOTE: the Storefront API v2 docs authenticate with `shop_id` (the
|
|
12
|
-
// Shopify myshopify.com domain) + an optional `storefront_api_key`, and
|
|
13
|
-
// don't mention a client_code param on this endpoint at all -- that's a
|
|
14
|
-
// holdover from Tagalys' older v1 API. Mapped below as best guess:
|
|
15
|
-
// BASE_URL -> used directly (docs say it's region-specific,
|
|
16
|
-
// e.g. https://api-r1.tagalys.com -- assumed already
|
|
17
|
-
// resolved to the right region in the creds store)
|
|
18
|
-
// STORE_HANDLE -> expanded to the `shop_id` myshopify domain
|
|
19
|
-
// STOREFRONT_API_KEY -> sent as `api_key`
|
|
20
|
-
// CLIENT_CODE -> not used by /v2/search per the docs; left unused below.
|
|
21
|
-
// Flag if your account actually needs it sent somewhere.
|
|
22
|
-
const DEFAULT_INCLUDE = ['products', 'total_count'];
|
|
23
|
-
|
|
24
|
-
// Recursively flattens nested params into Rails/PHP-style bracket query
|
|
25
|
-
// params, e.g. { filter: { color: ['red'] } } -> filter[color][]=red
|
|
26
|
-
// and { filter: { price: { selected_min: 100 } } } -> filter[price][selected_min]=100
|
|
27
|
-
const appendParams = (searchParams, key, value) => {
|
|
28
|
-
if (value === undefined || value === null) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (Array.isArray(value)) {
|
|
32
|
-
value.forEach((item) => appendParams(searchParams, `${ key }[]`, item));
|
|
33
|
-
} else if (typeof value === 'object') {
|
|
34
|
-
Object.entries(value).forEach(([subKey, subValue]) => {
|
|
35
|
-
appendParams(searchParams, `${ key }[${ subKey }]`, subValue);
|
|
36
|
-
});
|
|
37
|
-
} else {
|
|
38
|
-
searchParams.append(key, value);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const useUrlAndQuery = async (state) => {
|
|
43
|
-
const { requestPayload, context } = state;
|
|
44
|
-
const { creds } = context;
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
BASE_URL,
|
|
48
|
-
STORE_HANDLE,
|
|
49
|
-
STOREFRONT_API_KEY,
|
|
50
|
-
} = creds;
|
|
51
|
-
const shopId = `${ STORE_HANDLE }.myshopify.com`;
|
|
52
|
-
const storefrontApiKey = STOREFRONT_API_KEY;
|
|
53
|
-
|
|
54
|
-
const searchParams = new URLSearchParams();
|
|
55
|
-
searchParams.append('shop_id', shopId);
|
|
56
|
-
if (storefrontApiKey) {
|
|
57
|
-
searchParams.append('api_key', storefrontApiKey);
|
|
58
|
-
}
|
|
59
|
-
Object.entries(requestPayload.query || {}).forEach(([key, value]) => {
|
|
60
|
-
appendParams(searchParams, key, value);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
requestPayload: {
|
|
65
|
-
...requestPayload,
|
|
66
|
-
url: `${ BASE_URL }${ requestPayload.url }?${ searchParams.toString() }`,
|
|
67
|
-
headers: {
|
|
68
|
-
Accept: 'application/json',
|
|
69
|
-
...requestPayload.headers,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const tagalysClient = new FetchClient({
|
|
76
|
-
pipeline: [
|
|
77
|
-
resolveCreds,
|
|
78
|
-
useUrlAndQuery,
|
|
79
|
-
'fetch',
|
|
80
|
-
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
81
|
-
],
|
|
82
|
-
});
|
|
5
|
+
const { DEFAULT_INCLUDE } = require('../tagalys/tagalys.constants');
|
|
6
|
+
const { tagalysClient } = require('../tagalys/tagalys.utils');
|
|
83
7
|
|
|
84
8
|
const argsWarden = new ArgsWarden([
|
|
85
9
|
['credsPayload', credsValidator],
|
|
@@ -96,6 +20,9 @@ const tagalysSearch = async (
|
|
|
96
20
|
sort, // e.g. 'price-asc'
|
|
97
21
|
page,
|
|
98
22
|
perPage,
|
|
23
|
+
country,
|
|
24
|
+
language,
|
|
25
|
+
segmentTag,
|
|
99
26
|
} = {},
|
|
100
27
|
) => {
|
|
101
28
|
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
@@ -106,9 +33,16 @@ const tagalysSearch = async (
|
|
|
106
33
|
return rejectResponse;
|
|
107
34
|
}
|
|
108
35
|
|
|
36
|
+
// A search can be both redirected and spelling-corrected in the same
|
|
37
|
+
// response -- redirected/redirectUrl and data (query_handling,
|
|
38
|
+
// original_query, etc.) both land on the response, see
|
|
39
|
+
// tagalys.utils.js#useRedirectResponse.
|
|
109
40
|
const response = await tagalysClient.fetch({
|
|
110
41
|
context: {
|
|
111
42
|
credsPayload,
|
|
43
|
+
country,
|
|
44
|
+
language,
|
|
45
|
+
segmentTag,
|
|
112
46
|
},
|
|
113
47
|
requestPayload: {
|
|
114
48
|
url: '/v2/search',
|
|
@@ -125,19 +59,12 @@ const tagalysSearch = async (
|
|
|
125
59
|
},
|
|
126
60
|
});
|
|
127
61
|
|
|
128
|
-
const { ok,
|
|
62
|
+
const { ok, error } = response;
|
|
129
63
|
if (!ok) {
|
|
130
64
|
logDeep({ error });
|
|
131
|
-
return { ok: false, error };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// A configured redirect takes precedence over the rest of the response --
|
|
135
|
-
// surface it plainly rather than making callers dig for it.
|
|
136
|
-
if (data.redirect_url) {
|
|
137
|
-
return { ok: true, redirected: true, redirectUrl: data.redirect_url, data };
|
|
138
65
|
}
|
|
139
66
|
|
|
140
|
-
return
|
|
67
|
+
return response;
|
|
141
68
|
};
|
|
142
69
|
|
|
143
70
|
const funcApiConfig = {
|
|
@@ -146,11 +73,10 @@ const funcApiConfig = {
|
|
|
146
73
|
|
|
147
74
|
module.exports = {
|
|
148
75
|
tagalysSearch,
|
|
149
|
-
tagalysClient,
|
|
150
76
|
funcApiConfig,
|
|
151
77
|
};
|
|
152
78
|
|
|
153
79
|
/*
|
|
154
80
|
curl -X POST "http://localhost:8000/tagalysSearch" \
|
|
155
|
-
-d '{ "credsPayload": { "credsPath": "tagalys.
|
|
81
|
+
-d '{ "credsPayload": { "credsPath": "tagalys.store" }, "query": "gold" }'
|
|
156
82
|
*/
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// https://tagalys.notion.site/Storefront-API-v2-20eacdd38c2080d58d3fd0cf6f24e435
|
|
2
|
+
|
|
3
|
+
const { credsValidator } = require('../validators');
|
|
4
|
+
const { ArgsWarden, logDeep, valueProvided } = require('../utils');
|
|
5
|
+
const { tagalysClient } = require('../tagalys/tagalys.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['query'],
|
|
10
|
+
['sections', (sections) => valueProvided(sections) && Object.keys(sections).length > 0],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
// `sections` is an object keyed by section_id, e.g.:
|
|
14
|
+
// {
|
|
15
|
+
// products: { count: 6, include: ['items', 'total_count'], scope: { gender: ['female'] } },
|
|
16
|
+
// collections: { count: 4 },
|
|
17
|
+
// searches: { count: 4 },
|
|
18
|
+
// }
|
|
19
|
+
// section_ids and their available options are configured per account by Tagalys.
|
|
20
|
+
const tagalysSearchSuggestionsGet = async (
|
|
21
|
+
credsPayload,
|
|
22
|
+
query,
|
|
23
|
+
sections,
|
|
24
|
+
) => {
|
|
25
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
26
|
+
credsPayload,
|
|
27
|
+
query,
|
|
28
|
+
sections,
|
|
29
|
+
});
|
|
30
|
+
if (rejectResponse) {
|
|
31
|
+
return rejectResponse;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// redirected/redirectUrl land on the response via tagalys.utils.js#useRedirectResponse
|
|
35
|
+
const response = await tagalysClient.fetch({
|
|
36
|
+
context: {
|
|
37
|
+
credsPayload,
|
|
38
|
+
},
|
|
39
|
+
requestPayload: {
|
|
40
|
+
url: '/v2/search_suggestions',
|
|
41
|
+
method: 'get',
|
|
42
|
+
query: {
|
|
43
|
+
query,
|
|
44
|
+
sections,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const { ok, error } = response;
|
|
50
|
+
if (!ok) {
|
|
51
|
+
logDeep({ error });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return response;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const funcApiConfig = {
|
|
58
|
+
argsWarden,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
tagalysSearchSuggestionsGet,
|
|
63
|
+
funcApiConfig,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
curl -X POST "http://localhost:8000/tagalysSearchSuggestionsGet" \
|
|
68
|
+
-d '{
|
|
69
|
+
"credsPayload": { "credsPath": "tagalys.au" },
|
|
70
|
+
"query": "shi",
|
|
71
|
+
"sections": {
|
|
72
|
+
"products": { "count": 6 },
|
|
73
|
+
"collections": { "count": 4 }
|
|
74
|
+
}
|
|
75
|
+
}'
|
|
76
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foxtware/mineral",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"bin": {
|
|
5
5
|
"mineral": "bin/mineral.js"
|
|
6
6
|
},
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"spin_off": "node _build_scripts/spinOff.js",
|
|
18
18
|
"serve": "PORT=8100 node server.js",
|
|
19
19
|
"start": "node server.js",
|
|
20
|
+
"zip": "sh ../shell_scripts/zip.sh",
|
|
20
21
|
"npm:publish": "node _build_scripts/publish.js"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
package/server.js
CHANGED
|
@@ -200,11 +200,13 @@ const logStartup = ({
|
|
|
200
200
|
if (api_dirs.length) {
|
|
201
201
|
console.log('Extra API dirs:', api_dirs.join(', '));
|
|
202
202
|
}
|
|
203
|
-
|
|
203
|
+
|
|
204
|
+
/*
|
|
204
205
|
console.log('Registered routes:');
|
|
205
206
|
for (const route of [...routeHandlers.keys()].sort()) {
|
|
206
207
|
console.log(route);
|
|
207
208
|
}
|
|
209
|
+
*/
|
|
208
210
|
};
|
|
209
211
|
|
|
210
212
|
const startServer = (options = {}) => {
|