prezense 0.0.0-stage → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli.js ADDED
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env node
2
+ // `prezense deploy` — publish a storefront built on your own computer to its
3
+ // Prezense store. Run it from the project's root folder:
4
+ //
5
+ // npx prezense deploy
6
+ //
7
+ // It reads the same PREZENSE_API_KEY and PREZENSE_PLATFORM_KEY the storefront
8
+ // uses (from the environment, then .env.local, then .env), uploads the source —
9
+ // never node_modules, build output, .git or .env files — and Prezense installs,
10
+ // builds and publishes it, then switches the store's live address over. A
11
+ // failed publish leaves the live site as it was.
12
+
13
+ import { spawn } from 'node:child_process';
14
+ import { existsSync, readFileSync } from 'node:fs';
15
+ import path from 'node:path';
16
+
17
+ const DEFAULT_DEPLOY_URL = 'https://deploy.prezense.app';
18
+ const POLL_MS = 3000;
19
+ const TIMEOUT_MS = 20 * 60 * 1000;
20
+ const MAX_UPLOAD_BYTES = 50 * 1024 * 1024;
21
+
22
+ // Never uploaded. `./x` entries are anchored at the project root; the rest
23
+ // match anywhere (nothing needs a nested node_modules or .git).
24
+ const EXCLUDES = [
25
+ 'node_modules', '.git', '.DS_Store',
26
+ './.next', './.svelte-kit', './build', './.vercel', './.turbo', './.cache',
27
+ './.env', './.env.*',
28
+ ];
29
+
30
+ const HELP = `Usage: prezense deploy [folder]
31
+
32
+ Publishes the storefront in [folder] (default: the current folder) to the
33
+ Prezense store whose keys it uses. Reads PREZENSE_API_KEY and
34
+ PREZENSE_PLATFORM_KEY from the environment, .env.local or .env.
35
+
36
+ Copy those keys from the Prezense app: Settings → Your own agents.`;
37
+
38
+ function readEnvFile(file) {
39
+ const values = {};
40
+ if (!existsSync(file)) return values;
41
+ for (const line of readFileSync(file, 'utf8').split(/\r?\n/)) {
42
+ const m = line.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
43
+ if (!m) continue;
44
+ let value = m[2];
45
+ if (/^(['"]).*\1$/.test(value)) value = value.slice(1, -1);
46
+ else value = value.replace(/\s+#.*$/, '');
47
+ values[m[1]] = value;
48
+ }
49
+ return values;
50
+ }
51
+
52
+ function setting(name, dir) {
53
+ return process.env[name]
54
+ || readEnvFile(path.join(dir, '.env.local'))[name]
55
+ || readEnvFile(path.join(dir, '.env'))[name]
56
+ || '';
57
+ }
58
+
59
+ function packSource(dir) {
60
+ return new Promise((resolve, reject) => {
61
+ const args = ['czf', '-', ...EXCLUDES.map((p) => `--exclude=${p}`), '-C', dir, '.'];
62
+ // COPYFILE_DISABLE stops macOS tar adding ._ metadata files.
63
+ const tar = spawn('tar', args, { env: { ...process.env, COPYFILE_DISABLE: '1' } });
64
+ const chunks = [];
65
+ let size = 0;
66
+ let stderr = '';
67
+ tar.stdout.on('data', (c) => {
68
+ size += c.length;
69
+ chunks.push(c);
70
+ });
71
+ tar.stderr.on('data', (c) => { stderr += c; });
72
+ tar.on('error', (err) => reject(new Error(`couldn't run tar (${err.message})`)));
73
+ tar.on('close', (code) => {
74
+ if (code !== 0) reject(new Error(`tar failed: ${stderr.trim() || `exit ${code}`}`));
75
+ else resolve(Buffer.concat(chunks, size));
76
+ });
77
+ });
78
+ }
79
+
80
+ async function call(url, init) {
81
+ let res;
82
+ try {
83
+ res = await fetch(url, init);
84
+ } catch (err) {
85
+ throw new Error(`couldn't reach Prezense at ${url} (${err.cause?.code || err.message})`);
86
+ }
87
+ const body = await res.json().catch(() => ({}));
88
+ if (!res.ok) throw new Error(body.error || `Prezense answered ${res.status}`);
89
+ return body;
90
+ }
91
+
92
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
93
+
94
+ async function deploy(folder) {
95
+ const dir = path.resolve(folder || '.');
96
+ if (!existsSync(path.join(dir, 'package.json'))) {
97
+ throw new Error(`there's no package.json in ${dir} — run this from your storefront's root folder`);
98
+ }
99
+ const apiKey = setting('PREZENSE_API_KEY', dir);
100
+ const platformKey = setting('PREZENSE_PLATFORM_KEY', dir);
101
+ if (!apiKey || !platformKey) {
102
+ throw new Error('PREZENSE_API_KEY and PREZENSE_PLATFORM_KEY are not set. Copy them into .env.local from Settings → Your own agents in the Prezense app.');
103
+ }
104
+ const base = (setting('PREZENSE_DEPLOY_URL', dir) || DEFAULT_DEPLOY_URL).replace(/\/+$/, '');
105
+ const headers = { 'x-api-key': apiKey, 'x-platform-key': platformKey };
106
+
107
+ console.log(`Packing ${dir}…`);
108
+ const archive = await packSource(dir);
109
+ if (archive.length > MAX_UPLOAD_BYTES) {
110
+ throw new Error(`the source is ${(archive.length / 1048576).toFixed(0)} MB packed — over the 50 MB limit. Leave large files out of the project folder.`);
111
+ }
112
+ console.log(`Uploading ${(archive.length / 1024).toFixed(0)} KB to store "${platformKey}"…`);
113
+ const { deployment } = await call(`${base}/v1/deployments`, {
114
+ method: 'POST',
115
+ headers: { ...headers, 'content-type': 'application/gzip' },
116
+ body: archive,
117
+ });
118
+
119
+ // Print each new progress line once. The server keeps a rolling tail, so
120
+ // match on the last line seen rather than on a count.
121
+ let lastLine = null;
122
+ const printNew = (log) => {
123
+ const from = lastLine === null ? 0 : log.lastIndexOf(lastLine) + 1;
124
+ for (const line of log.slice(from)) console.log(` ${line}`);
125
+ if (log.length) lastLine = log[log.length - 1];
126
+ };
127
+
128
+ const started = Date.now();
129
+ let current = deployment;
130
+ for (;;) {
131
+ printNew(current.log || []);
132
+ if (current.status === 'done') {
133
+ console.log(`\nPublished. Live at ${current.url}`);
134
+ return;
135
+ }
136
+ if (current.status === 'failed') {
137
+ throw new Error(`the publish failed: ${current.error || 'unknown error'}. Your live site is unchanged.`);
138
+ }
139
+ if (Date.now() - started > TIMEOUT_MS) {
140
+ throw new Error(`still ${current.status} after 20 minutes — check the Publish menu in the Prezense app.`);
141
+ }
142
+ await sleep(POLL_MS);
143
+ current = (await call(`${base}/v1/deployments/${encodeURIComponent(deployment.id)}`, { headers })).deployment;
144
+ }
145
+ }
146
+
147
+ const [command, folder] = process.argv.slice(2);
148
+ if (command === 'deploy') {
149
+ deploy(folder).catch((err) => {
150
+ console.error(`\nprezense deploy: ${err.message}`);
151
+ process.exit(1);
152
+ });
153
+ } else {
154
+ console.log(HELP);
155
+ process.exit(command && command !== 'help' && command !== '--help' && command !== '-h' ? 1 : 0);
156
+ }
package/collections.js ADDED
@@ -0,0 +1,30 @@
1
+ import { operation, text, number } from './graphql.js';
2
+
3
+ // A store's own collections (hand-picked or imported from another platform),
4
+ // each with its products in the collection's order. Storefront route:
5
+ // /collections/<handle>. Only published collections are returned.
6
+ //
7
+ // Not to be confused with products.collectionProducts, which filters products
8
+ // by the free-text `collection` field on each product.
9
+
10
+ export class Collections {
11
+ constructor(client) {
12
+ this.client = client;
13
+ }
14
+
15
+ /** Every published collection, A–Z. `data` selects Collection fields. */
16
+ async allCollections({ data, limit, offset }) {
17
+ const args = { limit: ['Int', number(limit)], offset: ['Int', number(offset)] };
18
+ return this.client.sendRequest(operation('query', 'getCollections', args, data), 'getCollections');
19
+ }
20
+
21
+ /** One collection by handle. Select `products { … }` in `data` for its products. */
22
+ async collection({ handle, data, limit, offset }) {
23
+ const args = {
24
+ handle: ['String!', text(handle)],
25
+ limit: ['Int', number(limit)],
26
+ offset: ['Int', number(offset)],
27
+ };
28
+ return this.client.sendRequest(operation('query', 'getCollection', args, data), 'getCollection');
29
+ }
30
+ }
package/currency.js ADDED
@@ -0,0 +1,92 @@
1
+ import { operation, text, number } from './graphql.js';
2
+
3
+ export class Currency {
4
+ constructor(client) {
5
+ this.client = client;
6
+ }
7
+
8
+ /**
9
+ * Detect the customer's currency based on their IP address.
10
+ * Requires X-Currency: auto header (set via currency: 'auto' in constructor)
11
+ * or X-Forwarded-For / X-Real-IP headers for GeoIP detection.
12
+ */
13
+ async detect() {
14
+ const query = `query {
15
+ detectCurrency {
16
+ detected
17
+ currency
18
+ country
19
+ source
20
+ }
21
+ }`;
22
+ return this.client.sendRequest({ query }, 'detectCurrency');
23
+ }
24
+
25
+ /**
26
+ * Get current exchange rates for a base currency.
27
+ * @param {Object} options
28
+ * @param {string} [options.baseCurrency] - Base currency code (defaults to merchant's base currency)
29
+ */
30
+ async rates({ baseCurrency } = {}) {
31
+ // Values go in as GraphQL variables, never spliced into the query text.
32
+ const args = { baseCurrency: ['String', text(baseCurrency || undefined)] };
33
+ const selection = `
34
+ baseCurrency
35
+ targetCurrency
36
+ rate
37
+ `;
38
+ return this.client.sendRequest(operation('query', 'getExchangeRates', args, selection), 'getExchangeRates');
39
+ }
40
+
41
+ /**
42
+ * Convert a specific price between two currencies.
43
+ * @param {Object} options
44
+ * @param {number} options.amount - Amount to convert
45
+ * @param {string} options.from - Source currency code
46
+ * @param {string} options.to - Target currency code
47
+ */
48
+ async convert({ amount, from, to }) {
49
+ const args = {
50
+ amount: ['Float!', number(amount)],
51
+ fromCurrency: ['String!', text(from)],
52
+ toCurrency: ['String!', text(to)],
53
+ };
54
+ const selection = `
55
+ originalAmount
56
+ convertedAmount
57
+ fromCurrency
58
+ toCurrency
59
+ rate
60
+ `;
61
+ return this.client.sendRequest(operation('query', 'convertPrice', args, selection), 'convertPrice');
62
+ }
63
+
64
+ /**
65
+ * Get all currency codes supported by the platform's exchange rate service.
66
+ */
67
+ async supported() {
68
+ const query = `query {
69
+ getSupportedCurrencies
70
+ }`;
71
+ return this.client.sendRequest({ query }, 'getSupportedCurrencies');
72
+ }
73
+
74
+ /**
75
+ * Get the merchant's currency settings.
76
+ */
77
+ async settings() {
78
+ const query = `query {
79
+ getCurrencySettings {
80
+ baseCurrency
81
+ multiCurrencyEnabled
82
+ conversionMode
83
+ supportedCurrencies {
84
+ currencyCode
85
+ manualRate
86
+ enabled
87
+ }
88
+ }
89
+ }`;
90
+ return this.client.sendRequest({ query }, 'getCurrencySettings');
91
+ }
92
+ }
package/fraud.js ADDED
@@ -0,0 +1,59 @@
1
+ export class Fraud {
2
+ constructor(client) {
3
+ this.client = client;
4
+ }
5
+
6
+ // Every value goes in as a GraphQL variable, never spliced into the query
7
+ // text — cart ids and codes come from the shopper's request.
8
+
9
+ /**
10
+ * Assess the fraud risk of a cart before authorizing payment.
11
+ */
12
+ async assessCartFraudRisk({ cartID, data }) {
13
+ const query = `query ($cartID: String!) {
14
+ assessCartFraudRisk(cartID: $cartID) {
15
+ ${data.trim()}
16
+ }
17
+ }`;
18
+ return this.client.sendRequest({ query, variables: { cartID } }, 'assessCartFraudRisk');
19
+ }
20
+
21
+ /**
22
+ * Issue an email OTP fraud challenge for the cart. The code is emailed to
23
+ * the cart's customer email; the response carries only a masked hint.
24
+ */
25
+ async issueFraudChallenge({ cartID, data }) {
26
+ const query = `mutation ($cartID: String!) {
27
+ issueFraudChallenge(cartID: $cartID) {
28
+ ${data.trim()}
29
+ }
30
+ }`;
31
+ return this.client.sendRequest({ query, variables: { cartID } }, 'issueFraudChallenge');
32
+ }
33
+
34
+ /**
35
+ * Verify a previously issued fraud challenge code.
36
+ */
37
+ async verifyFraudChallenge({ cartID, code, data }) {
38
+ const query = `mutation ($cartID: String!, $code: String!) {
39
+ verifyFraudChallenge(cartID: $cartID, code: $code) {
40
+ ${data.trim()}
41
+ }
42
+ }`;
43
+ return this.client.sendRequest({ query, variables: { cartID, code } }, 'verifyFraudChallenge');
44
+ }
45
+
46
+ /**
47
+ * Report a Stripe chargeback against an order. Pushes high-confidence
48
+ * entries to the shared fraud blocklist.
49
+ */
50
+ async reportChargeback({ order_id, stripe_charge_id, data }) {
51
+ const query = `mutation ($orderId: String!, $stripeChargeId: String) {
52
+ reportChargeback(orderId: $orderId, stripeChargeId: $stripeChargeId) {
53
+ ${data.trim()}
54
+ }
55
+ }`;
56
+ const variables = { orderId: order_id, stripeChargeId: stripe_charge_id };
57
+ return this.client.sendRequest({ query, variables }, 'reportChargeback');
58
+ }
59
+ }
package/gift_cards.js ADDED
@@ -0,0 +1,35 @@
1
+ import { operation, text } from './graphql.js';
2
+
3
+ // Gift cards at checkout. Applying a card takes what it covers off the cart's
4
+ // total; charge the shopper only the returned `total` (0 = nothing to charge,
5
+ // create the order without a payment). The card's balance is drawn down when
6
+ // the order is created.
7
+ //
8
+ // GiftCardApplication fields: cartID, giftCardAmount, total, last4.
9
+ // GiftCardBalance fields: last4, balance, currency, expiresAt.
10
+
11
+ const APPLICATION = 'cartID giftCardAmount total last4';
12
+
13
+ export class GiftCards {
14
+ constructor(client) {
15
+ this.client = client;
16
+ }
17
+
18
+ /** A card's balance by its code. */
19
+ async balance({ code, data = 'last4 balance currency expiresAt' }) {
20
+ const args = { code: ['String!', text(code)] };
21
+ return this.client.sendRequest(operation('query', 'getGiftCardBalance', args, data), 'getGiftCardBalance');
22
+ }
23
+
24
+ /** Pay part or all of a cart with a card (replaces one already applied). */
25
+ async apply({ cartID, code, data = APPLICATION }) {
26
+ const args = { cartID: ['String!', text(cartID)], code: ['String!', text(code)] };
27
+ return this.client.sendRequest(operation('mutation', 'applyGiftCard', args, data), 'applyGiftCard');
28
+ }
29
+
30
+ /** Take the card off a cart. */
31
+ async remove({ cartID, data = APPLICATION }) {
32
+ const args = { cartID: ['String!', text(cartID)] };
33
+ return this.client.sendRequest(operation('mutation', 'removeGiftCard', args, data), 'removeGiftCard');
34
+ }
35
+ }
package/graphql.js ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Builds the SDK's GraphQL operations.
3
+ *
4
+ * Every value a caller passes goes to the server as a GraphQL variable,
5
+ * never spliced into the query text, so a shopper's name, address or search
6
+ * containing a quote or backslash can't change what the query does.
7
+ *
8
+ * The query text used to be built with template strings, which quietly
9
+ * accepted loose types: a quantity read from a form ("2") became the number
10
+ * 2, a numeric product ID (4) became the text "4". Variables are strictly
11
+ * typed, so the converters below turn each value into what the old query
12
+ * text sent, and existing storefront code keeps working.
13
+ */
14
+
15
+ /** Text for a String argument. null and undefined pass through. */
16
+ export function text(value) {
17
+ return value == null ? value : String(value);
18
+ }
19
+
20
+ /** A number for an Int or Float argument. null and undefined pass through. */
21
+ export function number(value) {
22
+ return value == null ? value : Number(value);
23
+ }
24
+
25
+ /** A Boolean argument: true, or the text "true". null and undefined pass through. */
26
+ export function bool(value) {
27
+ return value == null ? value : String(value) === 'true';
28
+ }
29
+
30
+ /** A list of Strings. */
31
+ export function textList(values) {
32
+ return Array.isArray(values) ? values.map(text) : values;
33
+ }
34
+
35
+ /**
36
+ * An input object whose fields are all text. snake_case keys become
37
+ * camelCase, and fields set to null or undefined are left out, as before.
38
+ */
39
+ export function textInput(fields) {
40
+ return Object.fromEntries(
41
+ Object.entries(fields)
42
+ .filter(([, value]) => value != null)
43
+ .map(([key, value]) => [
44
+ key.replace(/_([a-z0-9])/g, (_, char) => char.toUpperCase()),
45
+ typeof value === 'object' ? value : text(value),
46
+ ]),
47
+ );
48
+ }
49
+
50
+ /**
51
+ * One operation on one root field, as `{ query, variables }` for
52
+ * `sendRequest`. `args` maps each argument name to [GraphQL type, value]. An
53
+ * argument whose value is undefined is left out of the query, as the old
54
+ * queries did, so the server's own default for it applies. `selection` is the
55
+ * caller's field selection (the `data` string), for fields that return an
56
+ * object.
57
+ */
58
+ export function operation(kind, field, args, selection) {
59
+ const given = Object.entries(args).filter(([, [, value]]) => value !== undefined);
60
+ const declarations = given.map(([name, [type]]) => `$${name}: ${type}`).join(', ');
61
+ const argumentList = given.map(([name]) => `${name}: $${name}`).join(', ');
62
+ const variables = Object.fromEntries(given.map(([name, [, value]]) => [name, value]));
63
+
64
+ const query = `${kind}${given.length ? ` (${declarations})` : ''} {
65
+ ${field}${given.length ? `(${argumentList})` : ''}${selection === undefined ? '' : ` { ${selection.trim()} }`}
66
+ }`;
67
+ return { query, variables };
68
+ }
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Prezense } from './prezanse.js';
2
+
package/locations.js ADDED
@@ -0,0 +1,33 @@
1
+ import { operation, text, number } from './graphql.js';
2
+
3
+ // Every value goes in as a GraphQL variable (graphql.js), never spliced into
4
+ // the query text.
5
+
6
+ export class Locations {
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+
11
+ async storeLocations({ data, limit, offset }) {
12
+ const args = { limit: ['Int', number(limit)], offset: ['Int', number(offset)] };
13
+ return this.client.sendRequest(operation('query', 'getAllStoreLocations', args, data), 'getAllStoreLocations');
14
+ }
15
+
16
+ async storeLocationsByCountry({ country, data, limit, offset }) {
17
+ const args = {
18
+ country: ['String!', text(country)],
19
+ limit: ['Int', number(limit)],
20
+ offset: ['Int', number(offset)],
21
+ };
22
+ return this.client.sendRequest(operation('query', 'getStoreLocationsByCountry', args, data), 'getStoreLocationsByCountry');
23
+ }
24
+
25
+ async storeLocationsByCity({ city, data, limit, offset }) {
26
+ const args = {
27
+ city: ['String!', text(city)],
28
+ limit: ['Int', number(limit)],
29
+ offset: ['Int', number(offset)],
30
+ };
31
+ return this.client.sendRequest(operation('query', 'getStoreLocationsByCity', args, data), 'getStoreLocationsByCity');
32
+ }
33
+ }
package/loyalty.js ADDED
@@ -0,0 +1,78 @@
1
+ import { operation, text, number } from './graphql.js';
2
+
3
+ // Every value goes in as a GraphQL variable, never spliced into the query
4
+ // text.
5
+
6
+ export class Loyalty {
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+
11
+ async getStatus({ email, fingerprint, data }) {
12
+ const args = { email: ['String!', text(email)], fingerprint: ['String!', text(fingerprint)] };
13
+ return this.client.sendRequest(operation('query', 'getCustomerLoyaltyStatus', args, data), 'getCustomerLoyaltyStatus');
14
+ }
15
+
16
+ // The store's program rules and tiers — no customer, so no sign-in needed.
17
+ async getProgram({ data }) {
18
+ const query = `query {
19
+ getLoyaltyProgram {
20
+ ${data.trim()}
21
+ }
22
+ }`;
23
+ return this.client.sendRequest({ query }, 'getLoyaltyProgram');
24
+ }
25
+
26
+ // A signed-in customer's own points history, newest first.
27
+ async getHistory({ email, fingerprint, limit = 20, offset = 0, data }) {
28
+ const query = `
29
+ query GetCustomerLoyaltyHistory($email: String!, $fingerprint: String!, $limit: Int!, $offset: Int!) {
30
+ getCustomerLoyaltyHistory(email: $email, fingerprint: $fingerprint, limit: $limit, offset: $offset) {
31
+ ${data.trim()}
32
+ }
33
+ }
34
+ `;
35
+ const variables = { email, fingerprint, limit, offset };
36
+ return this.client.sendRequest({ query, variables }, 'getCustomerLoyaltyHistory');
37
+ }
38
+
39
+ async getAvailableRewards({ email, fingerprint, cartID, data }) {
40
+ const args = {
41
+ email: ['String!', text(email)],
42
+ fingerprint: ['String!', text(fingerprint)],
43
+ cartID: ['String!', text(cartID)],
44
+ };
45
+ return this.client.sendRequest(operation('query', 'getAvailableRewards', args, data), 'getAvailableRewards');
46
+ }
47
+
48
+ async previewRedemption({ email, fingerprint, cartID, points, data }) {
49
+ const args = {
50
+ email: ['String!', text(email)],
51
+ fingerprint: ['String!', text(fingerprint)],
52
+ cartID: ['String!', text(cartID)],
53
+ points: ['Int!', number(points)],
54
+ };
55
+ return this.client.sendRequest(operation('query', 'previewLoyaltyRedemption', args, data), 'previewLoyaltyRedemption');
56
+ }
57
+
58
+ async applyRedemption({ email, fingerprint, cartID, points, data }) {
59
+ const input = {
60
+ email: text(email),
61
+ fingerprint: text(fingerprint),
62
+ cartID: text(cartID),
63
+ points: number(points),
64
+ };
65
+ const args = { input: ['ApplyLoyaltyRedemptionInput!', input] };
66
+ return this.client.sendRequest(operation('mutation', 'applyLoyaltyRedemption', args, data), 'applyLoyaltyRedemption');
67
+ }
68
+
69
+ async removeRedemption({ email, fingerprint, cartID, data }) {
70
+ const input = {
71
+ email: text(email),
72
+ fingerprint: text(fingerprint),
73
+ cartID: text(cartID),
74
+ };
75
+ const args = { input: ['RemoveLoyaltyRedemptionInput!', input] };
76
+ return this.client.sendRequest(operation('mutation', 'removeLoyaltyRedemption', args, data), 'removeLoyaltyRedemption');
77
+ }
78
+ }
package/media.js ADDED
@@ -0,0 +1,87 @@
1
+ import { operation, text, number, textList } from './graphql.js';
2
+
3
+ // Every value goes in as a GraphQL variable (graphql.js), never spliced into
4
+ // the query text.
5
+
6
+ export class Media {
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+
11
+ async image({ imageID }) {
12
+ const args = { imageID: ['String!', text(imageID)] };
13
+ return this.client.sendRequest(operation('query', 'getImageByID', args), 'getImageByID');
14
+ }
15
+
16
+ async video({ videoID }) {
17
+ const args = { videoID: ['String!', text(videoID)] };
18
+ return this.client.sendRequest(operation('query', 'getVideoByID', args), 'getVideoByID');
19
+ }
20
+
21
+ async audio({ audioID }) {
22
+ const args = { audioID: ['String!', text(audioID)] };
23
+ return this.client.sendRequest(operation('query', 'getAudioByID', args), 'getAudioByID');
24
+ }
25
+
26
+ async productImages({ productID, limit, offset }) {
27
+ const args = {
28
+ productID: ['String!', text(productID)],
29
+ limit: ['Int', number(limit)],
30
+ offset: ['Int', number(offset)],
31
+ };
32
+ return this.client.sendRequest(operation('query', 'getAllImagesOfProduct', args), 'getAllImagesOfProduct');
33
+ }
34
+
35
+ async productVideos({ productID, limit, offset }) {
36
+ const args = {
37
+ productID: ['String!', text(productID)],
38
+ limit: ['Int', number(limit)],
39
+ offset: ['Int', number(offset)],
40
+ };
41
+ return this.client.sendRequest(operation('query', 'getAllVideosOfProduct', args), 'getAllVideosOfProduct');
42
+ }
43
+
44
+ async productAudio({ productID, limit, offset }) {
45
+ const args = {
46
+ productID: ['String!', text(productID)],
47
+ limit: ['Int', number(limit)],
48
+ offset: ['Int', number(offset)],
49
+ };
50
+ return this.client.sendRequest(operation('query', 'getAllAudioOfProduct', args), 'getAllAudioOfProduct');
51
+ }
52
+
53
+ async imagesByID({ imageIDs }) {
54
+ const args = { imageIDs: ['[String!]!', textList(imageIDs)] };
55
+ return this.client.sendRequest(operation('query', 'getListOfImagesByIDs', args), 'getListOfImagesByIDs');
56
+ }
57
+
58
+ async videosByID({ videoIDs }) {
59
+ const args = { videoIDs: ['[String!]!', textList(videoIDs)] };
60
+ return this.client.sendRequest(operation('query', 'getListOfVideosByIDs', args), 'getListOfVideosByIDs');
61
+ }
62
+
63
+ async audioByID({ audioIDs }) {
64
+ const args = { audioIDs: ['[String!]!', textList(audioIDs)] };
65
+ return this.client.sendRequest(operation('query', 'getListOfAudioByIDs', args), 'getListOfAudioByIDs');
66
+ }
67
+
68
+ async globalMediaByID({ mediaIDs }) {
69
+ const args = { mediaIDs: ['[String!]!', textList(mediaIDs)] };
70
+ const selection = `
71
+ mediaID
72
+ mediaType
73
+ mediaURL
74
+ `;
75
+ return this.client.sendRequest(operation('query', 'getListOfGlobalMediaByID', args, selection), 'getListOfGlobalMediaByID');
76
+ }
77
+
78
+ async allGlobalMedia({ limit, offset }) {
79
+ const args = { limit: ['Int', number(limit)], offset: ['Int', number(offset)] };
80
+ const selection = `
81
+ mediaID
82
+ mediaType
83
+ mediaURL
84
+ `;
85
+ return this.client.sendRequest(operation('query', 'getAllGlobalMediaOfStore', args, selection), 'getAllGlobalMediaOfStore');
86
+ }
87
+ }