New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@shopify/shopify-api

Package Overview
Dependencies
Maintainers
19
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/shopify-api - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

dist/auth/session/types.d.ts

5

CHANGELOG.md

@@ -10,2 +10,7 @@ # Changelog

## [1.3.0] - 2021-05-12
### Added
- Added Storefront API client under `Shopify.Clients.Storefront`
- Add `isActive()` method to `Session` class to check if session is active, replace `Session` with `SessionInterface` when used as a type [#153](https://github.com/Shopify/shopify-node-api/pull/153)
## [1.2.1] - 2021-03-26

@@ -12,0 +17,0 @@ ### Added

6

dist/auth/session/session_storage.d.ts

@@ -1,2 +0,2 @@

import { Session } from './session';
import { SessionInterface } from './types';
/**

@@ -11,3 +11,3 @@ * Defines the strategy to be used to store sessions for the Shopify App.

*/
storeSession(session: Session): Promise<boolean>;
storeSession(session: SessionInterface): Promise<boolean>;
/**

@@ -18,3 +18,3 @@ * Loads a session from storage.

*/
loadSession(id: string): Promise<Session | undefined>;
loadSession(id: string): Promise<SessionInterface | undefined>;
/**

@@ -21,0 +21,0 @@ * Deletes a session from storage.

import { OnlineAccessInfo } from '../oauth/types';
import { SessionInterface } from './types';
/**
* Stores App information from logged in merchants so they can make authenticated requests to the Admin API.
*/
declare class Session {
declare class Session implements SessionInterface {
readonly id: string;

@@ -16,4 +17,5 @@ static cloneSession(session: Session, newId: string): Session;

constructor(id: string);
isActive(): boolean;
}
export { Session };
//# sourceMappingURL=session.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Session = void 0;
var context_1 = require("../../context");
/**

@@ -22,4 +23,11 @@ * Stores App information from logged in merchants so they can make authenticated requests to the Admin API.

};
Session.prototype.isActive = function () {
var scopesUnchanged = context_1.Context.SCOPES.equals(this.scope);
if (scopesUnchanged && this.accessToken && (!this.expires || this.expires >= new Date())) {
return true;
}
return false;
};
return Session;
}());
exports.Session = Session;

@@ -1,12 +0,12 @@

import { Session } from '../session';
import { SessionInterface } from '../types';
import { SessionStorage } from '../session_storage';
export declare class CustomSessionStorage implements SessionStorage {
readonly storeCallback: (session: Session) => Promise<boolean>;
readonly loadCallback: (id: string) => Promise<Session | Record<string, unknown> | undefined>;
readonly storeCallback: (session: SessionInterface) => Promise<boolean>;
readonly loadCallback: (id: string) => Promise<SessionInterface | Record<string, unknown> | undefined>;
readonly deleteCallback: (id: string) => Promise<boolean>;
constructor(storeCallback: (session: Session) => Promise<boolean>, loadCallback: (id: string) => Promise<Session | Record<string, unknown> | undefined>, deleteCallback: (id: string) => Promise<boolean>);
storeSession(session: Session): Promise<boolean>;
loadSession(id: string): Promise<Session | undefined>;
constructor(storeCallback: (session: SessionInterface) => Promise<boolean>, loadCallback: (id: string) => Promise<SessionInterface | Record<string, unknown> | undefined>, deleteCallback: (id: string) => Promise<boolean>);
storeSession(session: SessionInterface): Promise<boolean>;
loadSession(id: string): Promise<SessionInterface | undefined>;
deleteSession(id: string): Promise<boolean>;
}
//# sourceMappingURL=custom.d.ts.map

@@ -1,9 +0,9 @@

import { Session } from '../session';
import { SessionInterface } from '../types';
import { SessionStorage } from '../session_storage';
export declare class MemorySessionStorage implements SessionStorage {
private sessions;
storeSession(session: Session): Promise<boolean>;
loadSession(id: string): Promise<Session | undefined>;
storeSession(session: SessionInterface): Promise<boolean>;
loadSession(id: string): Promise<SessionInterface | undefined>;
deleteSession(id: string): Promise<boolean>;
}
//# sourceMappingURL=memory.d.ts.map

@@ -1,3 +0,3 @@

import { SessionStorage } from './auth/session';
import { AuthScopes } from './auth/scopes';
import { SessionStorage } from './auth/session/session_storage';
export interface ContextParams {

@@ -14,2 +14,3 @@ API_KEY: string;

USER_AGENT_PREFIX?: string;
PRIVATE_APP_STOREFRONT_ACCESS_TOKEN?: string;
}

@@ -31,2 +32,3 @@ export declare enum ApiVersion {

AccessToken = "X-Shopify-Access-Token",
StorefrontAccessToken = "X-Shopify-Storefront-Access-Token",
Hmac = "X-Shopify-Hmac-Sha256",

@@ -33,0 +35,0 @@ Topic = "X-Shopify-Topic",

@@ -21,2 +21,3 @@ "use strict";

ShopifyHeader["AccessToken"] = "X-Shopify-Access-Token";
ShopifyHeader["StorefrontAccessToken"] = "X-Shopify-Storefront-Access-Token";
ShopifyHeader["Hmac"] = "X-Shopify-Hmac-Sha256";

@@ -23,0 +24,0 @@ ShopifyHeader["Topic"] = "X-Shopify-Topic";

import { RequestReturn } from '../http_client/types';
import { GraphqlParams } from './types';
export interface AccessTokenHeader {
header: string;
value: string;
}
export declare class GraphqlClient {
readonly domain: string;
readonly token?: string | undefined;
readonly accessToken?: string | undefined;
protected baseApiPath: string;
private readonly client;
constructor(domain: string, token?: string | undefined);
constructor(domain: string, accessToken?: string | undefined);
query(params: GraphqlParams): Promise<RequestReturn>;
protected getAccessTokenHeader(): AccessTokenHeader;
}
//# sourceMappingURL=graphql_client.d.ts.map

@@ -12,6 +12,7 @@ "use strict";

var GraphqlClient = /** @class */ (function () {
function GraphqlClient(domain, token) {
function GraphqlClient(domain, accessToken) {
this.domain = domain;
this.token = token;
if (!context_1.Context.IS_PRIVATE_APP && !token) {
this.accessToken = accessToken;
this.baseApiPath = '/admin/api';
if (!context_1.Context.IS_PRIVATE_APP && !accessToken) {
throw new ShopifyErrors.MissingRequiredArgument('Missing access token when creating GraphQL client');

@@ -23,3 +24,3 @@ }

return tslib_1.__awaiter(this, void 0, void 0, function () {
var path, dataType;
var accessTokenHeader, path, dataType;
var _a;

@@ -30,4 +31,5 @@ return tslib_1.__generator(this, function (_b) {

}
params.extraHeaders = tslib_1.__assign((_a = {}, _a[base_types_1.ShopifyHeader.AccessToken] = context_1.Context.IS_PRIVATE_APP ? context_1.Context.API_SECRET_KEY : this.token, _a), params.extraHeaders);
path = "/admin/api/" + context_1.Context.API_VERSION + "/graphql.json";
accessTokenHeader = this.getAccessTokenHeader();
params.extraHeaders = tslib_1.__assign((_a = {}, _a[accessTokenHeader.header] = accessTokenHeader.value, _a), params.extraHeaders);
path = this.baseApiPath + "/" + context_1.Context.API_VERSION + "/graphql.json";
if (typeof params.data === 'object') {

@@ -43,4 +45,10 @@ dataType = types_1.DataType.JSON;

};
GraphqlClient.prototype.getAccessTokenHeader = function () {
return {
header: base_types_1.ShopifyHeader.AccessToken,
value: context_1.Context.IS_PRIVATE_APP ? context_1.Context.API_SECRET_KEY : this.accessToken,
};
};
return GraphqlClient;
}());
exports.GraphqlClient = GraphqlClient;
import { RestClient as Rest } from './rest';
import { GraphqlClient as Graphql } from './graphql';
import { StorefrontClient as Storefront } from './graphql/storefront_client';
declare const ShopifyClients: {
Rest: typeof Rest;
Graphql: typeof Graphql;
Storefront: typeof Storefront;
};

@@ -7,0 +9,0 @@ export default ShopifyClients;

@@ -6,7 +6,9 @@ "use strict";

var graphql_1 = require("./graphql");
var storefront_client_1 = require("./graphql/storefront_client");
var ShopifyClients = {
Rest: rest_1.RestClient,
Graphql: graphql_1.GraphqlClient,
Storefront: storefront_client_1.StorefrontClient,
};
exports.ShopifyClients = ShopifyClients;
exports.default = ShopifyClients;

@@ -23,13 +23,11 @@ "use strict";

var ret, link, pageInfo, links, links_1, links_1_1, link_1, parsedLink, linkRel, linkUrl, linkFields, linkPageToken;
var e_1, _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
var _a, e_1, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
params.extraHeaders = tslib_1.__assign({}, params.extraHeaders);
params.extraHeaders[base_types_1.ShopifyHeader.AccessToken] = context_1.Context.IS_PRIVATE_APP
? context_1.Context.API_SECRET_KEY : this.accessToken;
params.extraHeaders = tslib_1.__assign((_a = {}, _a[base_types_1.ShopifyHeader.AccessToken] = context_1.Context.IS_PRIVATE_APP ? context_1.Context.API_SECRET_KEY : this.accessToken, _a), params.extraHeaders);
params.path = this.getRestPath(params.path);
return [4 /*yield*/, _super.prototype.request.call(this, params)];
case 1:
ret = (_b.sent());
ret = (_c.sent());
link = ret.headers.get('link');

@@ -73,3 +71,3 @@ if (params.query && link !== undefined) {

try {
if (links_1_1 && !links_1_1.done && (_a = links_1.return)) _a.call(links_1);
if (links_1_1 && !links_1_1.done && (_b = links_1.return)) _b.call(links_1);
}

@@ -90,4 +88,5 @@ finally { if (e_1) throw e_1.error; }

RestClient.prototype.buildRequestParams = function (newPageUrl) {
var pattern = "^/admin/api/[^/]+/(.*).json$";
var url = new URL(newPageUrl);
var path = url.pathname.replace(/^\/admin\/api\/[^/]+\/(.*)\.json$/, '$1');
var path = url.pathname.replace(new RegExp(pattern), '$1');
var query = querystring_1.default.decode(url.search.replace(/^\?(.*)/, '$1'));

@@ -94,0 +93,0 @@ return {

@@ -1,2 +0,2 @@

import { SessionStorage } from './auth/session';
import { SessionStorage } from './auth/session/session_storage';
import { ContextParams } from './base_types';

@@ -3,0 +3,0 @@ import { AuthScopes } from './auth/scopes';

@@ -6,3 +6,3 @@ "use strict";

var ShopifyErrors = tslib_1.__importStar(require("./error"));
var session_1 = require("./auth/session");
var memory_1 = require("./auth/session/storage/memory");
var base_types_1 = require("./base_types");

@@ -18,3 +18,3 @@ var scopes_1 = require("./auth/scopes");

IS_PRIVATE_APP: false,
SESSION_STORAGE: new session_1.MemorySessionStorage(),
SESSION_STORAGE: new memory_1.MemorySessionStorage(),
initialize: function (params) {

@@ -61,2 +61,5 @@ var scopes;

}
if (params.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN) {
this.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN = params.PRIVATE_APP_STOREFRONT_ACCESS_TOKEN;
}
},

@@ -63,0 +66,0 @@ throwIfUninitialized: function () {

@@ -22,2 +22,3 @@ /// <reference types="node" />

Graphql: typeof import("./clients/graphql").GraphqlClient;
Storefront: typeof import("./clients/graphql/storefront_client").StorefrontClient;
};

@@ -36,2 +37,3 @@ Utils: {

validateShop: typeof import("./utils/shop-validator").default;
versionCompatible: typeof import("./utils/version-compatible").default;
withSession: typeof import("./utils/with-session").default;

@@ -38,0 +40,0 @@ };

export * from './base_types';
export * from './auth/oauth/types';
export * from './auth/types';
export * from './clients/types';

@@ -4,0 +4,0 @@ export * from './utils/types';

@@ -5,5 +5,5 @@ "use strict";

tslib_1.__exportStar(require("./base_types"), exports);
tslib_1.__exportStar(require("./auth/oauth/types"), exports);
tslib_1.__exportStar(require("./auth/types"), exports);
tslib_1.__exportStar(require("./clients/types"), exports);
tslib_1.__exportStar(require("./utils/types"), exports);
tslib_1.__exportStar(require("./webhooks/types"), exports);

@@ -12,2 +12,3 @@ import decodeSessionToken from './decode-session-token';

import validateShop from './shop-validator';
import versionCompatible from './version-compatible';
import withSession from './with-session';

@@ -26,2 +27,3 @@ declare const ShopifyUtils: {

validateShop: typeof validateShop;
versionCompatible: typeof versionCompatible;
withSession: typeof withSession;

@@ -28,0 +30,0 @@ };

@@ -15,2 +15,3 @@ "use strict";

var shop_validator_1 = tslib_1.__importDefault(require("./shop-validator"));
var version_compatible_1 = tslib_1.__importDefault(require("./version-compatible"));
var with_session_1 = tslib_1.__importDefault(require("./with-session"));

@@ -29,4 +30,5 @@ var ShopifyUtils = {

validateShop: shop_validator_1.default,
versionCompatible: version_compatible_1.default,
withSession: with_session_1.default,
};
exports.default = ShopifyUtils;

@@ -1,2 +0,2 @@

export declare const SHOPIFY_API_LIBRARY_VERSION = "1.2.1";
export declare const SHOPIFY_API_LIBRARY_VERSION = "1.3.0";
//# sourceMappingURL=version.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SHOPIFY_API_LIBRARY_VERSION = void 0;
exports.SHOPIFY_API_LIBRARY_VERSION = '1.2.1';
exports.SHOPIFY_API_LIBRARY_VERSION = '1.3.0';
/// <reference types="node" />
import http from 'http';
import { RegisterOptions, RegisterReturn, WebhookRegistryEntry } from './types';
import { DeliveryMethod, RegisterOptions, RegisterReturn, WebhookRegistryEntry } from './types';
interface RegistryInterface {

@@ -26,4 +26,6 @@ webhookRegistry: WebhookRegistryEntry[];

}
declare function buildCheckQuery(topic: string): string;
declare function buildQuery(topic: string, address: string, deliveryMethod?: DeliveryMethod, webhookId?: string): string;
declare const WebhooksRegistry: RegistryInterface;
export { WebhooksRegistry, RegistryInterface };
export { WebhooksRegistry, RegistryInterface, buildCheckQuery, buildQuery };
//# sourceMappingURL=registry.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebhooksRegistry = void 0;
exports.buildQuery = exports.buildCheckQuery = exports.WebhooksRegistry = void 0;
var tslib_1 = require("tslib");

@@ -41,6 +41,20 @@ var crypto_1 = require("crypto");

}
// 2020-07 onwards
function versionSupportsEndpointField() {
return utils_1.default.versionCompatible(base_types_1.ApiVersion.July20);
}
function validateDeliveryMethod(deliveryMethod) {
if (deliveryMethod === types_1.DeliveryMethod.EventBridge && !versionSupportsEndpointField()) {
throw new ShopifyErrors.UnsupportedClientType("EventBridge webhooks are not supported in API version \"" + context_1.Context.API_VERSION + "\".");
}
}
function buildCheckQuery(topic) {
return "{\n webhookSubscriptions(first: 1, topics: " + topic + ") {\n edges {\n node {\n id\n callbackUrl\n }\n }\n }\n }";
var query = "{\n webhookSubscriptions(first: 1, topics: " + topic + ") {\n edges {\n node {\n id\n endpoint {\n __typename\n ... on WebhookHttpEndpoint {\n callbackUrl\n }\n ... on WebhookEventBridgeEndpoint {\n arn\n }\n }\n }\n }\n }\n }";
var legacyQuery = "{\n webhookSubscriptions(first: 1, topics: " + topic + ") {\n edges {\n node {\n id\n callbackUrl\n }\n }\n }\n }";
return versionSupportsEndpointField() ? query : legacyQuery;
}
exports.buildCheckQuery = buildCheckQuery;
function buildQuery(topic, address, deliveryMethod, webhookId) {
if (deliveryMethod === void 0) { deliveryMethod = types_1.DeliveryMethod.Http; }
validateDeliveryMethod(deliveryMethod);
var identifier;

@@ -67,2 +81,3 @@ if (webhookId) {

}
exports.buildQuery = buildQuery;
var WebhooksRegistry = {

@@ -73,8 +88,11 @@ webhookRegistry: [],

return tslib_1.__awaiter(this, void 0, void 0, function () {
var client, address, checkResult, checkBody, webhookId, mustRegister, success, body, result;
var client, address, checkResult, webhookId, mustRegister, node, endpointAddress, success, body, result;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
validateDeliveryMethod(deliveryMethod);
client = new graphql_client_1.GraphqlClient(shop, accessToken);
address = "https://" + context_1.Context.HOST_NAME + path;
address = deliveryMethod === types_1.DeliveryMethod.EventBridge
? path
: "https://" + context_1.Context.HOST_NAME + path;
return [4 /*yield*/, client.query({

@@ -85,7 +103,16 @@ data: buildCheckQuery(topic),

checkResult = _c.sent();
checkBody = checkResult.body;
mustRegister = true;
if (checkBody.data.webhookSubscriptions.edges.length) {
webhookId = checkBody.data.webhookSubscriptions.edges[0].node.id;
if (checkBody.data.webhookSubscriptions.edges[0].node.callbackUrl === address) {
if (checkResult.body.data.webhookSubscriptions.edges.length) {
node = checkResult.body.data.webhookSubscriptions.edges[0].node;
endpointAddress = '';
if ('endpoint' in node) {
endpointAddress = node.endpoint.__typename === 'WebhookHttpEndpoint'
? node.endpoint.callbackUrl
: node.endpoint.arn;
}
else {
endpointAddress = node.callbackUrl;
}
webhookId = node.id;
if (endpointAddress === address) {
mustRegister = false;

@@ -92,0 +119,0 @@ }

@@ -11,4 +11,4 @@ export declare enum DeliveryMethod {

accessToken: string;
webhookHandler: WebhookHandlerFunction;
deliveryMethod?: DeliveryMethod;
webhookHandler: WebhookHandlerFunction;
}

@@ -24,16 +24,27 @@ export interface RegisterReturn {

}
interface WebhookCheckResponseNode {
interface WebhookCheckResponseNode<T = {
endpoint: {
__typename: 'WebhookHttpEndpoint';
callbackUrl: string;
} | {
__typename: 'WebhookEventBridgeEndpoint';
arn: string;
};
}> {
node: {
id: string;
callbackUrl: string;
};
} & T;
}
export interface WebhookCheckResponse {
declare type WebhookCheckLegacyResponseNode = WebhookCheckResponseNode<{
callbackUrl: string;
}>;
export interface WebhookCheckResponse<T = WebhookCheckResponseNode> {
data: {
webhookSubscriptions: {
edges: WebhookCheckResponseNode[];
edges: T[];
};
};
}
export declare type WebhookCheckResponseLegacy = WebhookCheckResponse<WebhookCheckLegacyResponseNode>;
export {};
//# sourceMappingURL=types.d.ts.map
{
"name": "@shopify/shopify-api",
"version": "1.2.1",
"description": "Shopify Admin API Library for Node - accelerate development with support for authentication, graphql proxy, webhooks",
"version": "1.3.0",
"description": "Shopify API Library for Node - accelerate development with support for authentication, graphql proxy, webhooks",
"main": "dist/index.js",

@@ -37,3 +37,4 @@ "types": "dist/index.d.ts",

"webhook",
"Admin API"
"Admin API",
"Storefront API"
],

@@ -40,0 +41,0 @@ "dependencies": {

@@ -14,2 +14,4 @@ # `@shopify/shopify-api`

Once your app has access to the Admin API, you can also access the [Shopify Storefront API](https://shopify.dev/docs/storefront-api) to run GraphQL queries using the `unauthenticated_*` access scopes.
This library can be used in any application that has a Node.js backend, since it doesn't rely on any specific framework—you can include it alongside your preferred stack and only use the features that you need to build your app.

@@ -46,2 +48,3 @@

- [Make a GraphQL API call](docs/usage/graphql.md)
- [Make a Storefront API call](docs/usage/storefront.md)
- [Webhooks](docs/usage/webhooks.md)

@@ -48,0 +51,0 @@ - [Register a Webhook](docs/usage/webhooks.md#register-a-webhook)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc