@shopify/shopify-app-remix 1.2.1 → 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/README.md +6 -6
- package/build/cjs/react/components/AppProvider/AppProvider.js +35 -4
- package/build/cjs/server/authenticate/admin/billing/request.js +4 -2
- package/build/cjs/server/authenticate/public/appProxy/authenticate.js +7 -1
- package/build/cjs/server/boundary/index.js +6 -6
- package/build/cjs/server/clients/storefront/factory.js +35 -0
- package/build/cjs/server/shopify-app.js +7 -5
- package/build/cjs/server/types.js +1 -1
- package/build/cjs/server/unauthenticated/admin/factory.js +2 -2
- package/build/cjs/server/unauthenticated/helpers/get-offline-session.js +14 -0
- package/build/cjs/server/unauthenticated/storefront/factory.js +25 -0
- package/build/cjs/server/version.js +1 -1
- package/build/ts/react/components/AppProvider/AppProvider.d.ts +48 -8
- package/build/ts/react/components/AppProvider/AppProvider.d.ts.map +1 -1
- package/build/ts/react/components/AppProvider/AppProvider.doc.d.ts +4 -0
- package/build/ts/react/components/AppProvider/AppProvider.doc.d.ts.map +1 -0
- package/build/ts/react/components/AppProvider/AppProvider.doc.js +34 -0
- package/build/ts/react/components/AppProvider/AppProvider.doc.js.map +1 -0
- package/build/ts/react/components/AppProvider/AppProvider.js +35 -3
- package/build/ts/react/components/AppProvider/AppProvider.js.map +1 -1
- package/build/ts/server/__test-helpers/expect-admin-api-client.d.ts +1 -1
- package/build/ts/server/__test-helpers/expect-admin-api-client.d.ts.map +1 -1
- package/build/ts/server/__test-helpers/expect-storefront-api-client.d.ts +8 -0
- package/build/ts/server/__test-helpers/expect-storefront-api-client.d.ts.map +1 -0
- package/build/ts/server/__test-helpers/expect-storefront-api-client.js +57 -0
- package/build/ts/server/__test-helpers/expect-storefront-api-client.js.map +1 -0
- package/build/ts/server/__test-helpers/index.d.ts +1 -0
- package/build/ts/server/__test-helpers/index.d.ts.map +1 -1
- package/build/ts/server/__test-helpers/index.js +1 -0
- package/build/ts/server/__test-helpers/index.js.map +1 -1
- package/build/ts/server/authenticate/admin/authenticate.admin.doc.d.ts +4 -0
- package/build/ts/server/authenticate/admin/authenticate.admin.doc.d.ts.map +1 -0
- package/build/ts/server/authenticate/admin/authenticate.admin.doc.js +35 -0
- package/build/ts/server/authenticate/admin/authenticate.admin.doc.js.map +1 -0
- package/build/ts/server/authenticate/admin/authenticate.d.ts.map +1 -1
- package/build/ts/server/authenticate/admin/authenticate.js.map +1 -1
- package/build/ts/server/authenticate/admin/billing/authenticate.admin.billing.doc.d.ts +4 -0
- package/build/ts/server/authenticate/admin/billing/authenticate.admin.billing.doc.d.ts.map +1 -0
- package/build/ts/server/authenticate/admin/billing/authenticate.admin.billing.doc.js +26 -0
- package/build/ts/server/authenticate/admin/billing/authenticate.admin.billing.doc.js.map +1 -0
- package/build/ts/server/authenticate/admin/billing/request.d.ts +1 -1
- package/build/ts/server/authenticate/admin/billing/request.d.ts.map +1 -1
- package/build/ts/server/authenticate/admin/billing/request.js +2 -8
- package/build/ts/server/authenticate/admin/billing/request.js.map +1 -1
- package/build/ts/server/authenticate/admin/billing/types.d.ts +63 -55
- package/build/ts/server/authenticate/admin/billing/types.d.ts.map +1 -1
- package/build/ts/server/authenticate/admin/types.d.ts +66 -30
- package/build/ts/server/authenticate/admin/types.d.ts.map +1 -1
- package/build/ts/server/authenticate/helpers/add-response-headers.d.ts +2 -1
- package/build/ts/server/authenticate/helpers/add-response-headers.d.ts.map +1 -1
- package/build/ts/server/authenticate/helpers/add-response-headers.js.map +1 -1
- package/build/ts/server/authenticate/public/appProxy/authenticate.d.ts.map +1 -1
- package/build/ts/server/authenticate/public/appProxy/authenticate.js +4 -2
- package/build/ts/server/authenticate/public/appProxy/authenticate.js.map +1 -1
- package/build/ts/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.d.ts +4 -0
- package/build/ts/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.d.ts.map +1 -0
- package/build/ts/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.js +32 -0
- package/build/ts/server/authenticate/public/appProxy/authenticate.public.app-proxy.doc.js.map +1 -0
- package/build/ts/server/authenticate/public/appProxy/types.d.ts +64 -8
- package/build/ts/server/authenticate/public/appProxy/types.d.ts.map +1 -1
- package/build/ts/server/authenticate/public/checkout/authenticate.public.checkout.doc.d.ts +4 -0
- package/build/ts/server/authenticate/public/checkout/authenticate.public.checkout.doc.d.ts.map +1 -0
- package/build/ts/server/authenticate/public/checkout/authenticate.public.checkout.doc.js +21 -0
- package/build/ts/server/authenticate/public/checkout/authenticate.public.checkout.doc.js.map +1 -0
- package/build/ts/server/authenticate/public/checkout/types.d.ts +15 -13
- package/build/ts/server/authenticate/public/checkout/types.d.ts.map +1 -1
- package/build/ts/server/authenticate/public/types.d.ts +19 -17
- package/build/ts/server/authenticate/public/types.d.ts.map +1 -1
- package/build/ts/server/authenticate/webhooks/authenticate.webhooks.doc.d.ts +4 -0
- package/build/ts/server/authenticate/webhooks/authenticate.webhooks.doc.d.ts.map +1 -0
- package/build/ts/server/authenticate/webhooks/authenticate.webhooks.doc.js +20 -0
- package/build/ts/server/authenticate/webhooks/authenticate.webhooks.doc.js.map +1 -0
- package/build/ts/server/authenticate/webhooks/types.d.ts +103 -0
- package/build/ts/server/authenticate/webhooks/types.d.ts.map +1 -1
- package/build/ts/server/boundary/index.d.ts +6 -6
- package/build/ts/server/boundary/index.js +6 -6
- package/build/ts/server/clients/admin/authenticate.admin.api.doc.d.ts +4 -0
- package/build/ts/server/clients/admin/authenticate.admin.api.doc.d.ts.map +1 -0
- package/build/ts/server/clients/admin/authenticate.admin.api.doc.js +32 -0
- package/build/ts/server/clients/admin/authenticate.admin.api.doc.js.map +1 -0
- package/build/ts/server/clients/admin/factory.d.ts +1 -1
- package/build/ts/server/clients/admin/factory.d.ts.map +1 -1
- package/build/ts/server/clients/admin/factory.js.map +1 -1
- package/build/ts/server/clients/admin/graphql.d.ts +3 -15
- package/build/ts/server/clients/admin/graphql.d.ts.map +1 -1
- package/build/ts/server/clients/admin/graphql.js.map +1 -1
- package/build/ts/server/clients/admin/index.d.ts +1 -0
- package/build/ts/server/clients/admin/index.d.ts.map +1 -1
- package/build/ts/server/clients/admin/index.js +1 -0
- package/build/ts/server/clients/admin/index.js.map +1 -1
- package/build/ts/server/clients/admin/rest.d.ts +1 -1
- package/build/ts/server/clients/admin/rest.d.ts.map +1 -1
- package/build/ts/server/clients/admin/types.d.ts +105 -1
- package/build/ts/server/clients/admin/types.d.ts.map +1 -1
- package/build/ts/server/clients/index.d.ts +3 -0
- package/build/ts/server/clients/index.d.ts.map +1 -0
- package/build/ts/server/clients/index.js +6 -0
- package/build/ts/server/clients/index.js.map +1 -0
- package/build/ts/server/clients/storefront/authenticate.storefront.api.doc.d.ts +4 -0
- package/build/ts/server/clients/storefront/authenticate.storefront.api.doc.d.ts.map +1 -0
- package/build/ts/server/clients/storefront/authenticate.storefront.api.doc.js +32 -0
- package/build/ts/server/clients/storefront/authenticate.storefront.api.doc.js.map +1 -0
- package/build/ts/server/clients/storefront/factory.d.ts +8 -0
- package/build/ts/server/clients/storefront/factory.d.ts.map +1 -0
- package/build/ts/server/clients/storefront/factory.js +39 -0
- package/build/ts/server/clients/storefront/factory.js.map +1 -0
- package/build/ts/server/clients/storefront/index.d.ts +3 -0
- package/build/ts/server/clients/storefront/index.d.ts.map +1 -0
- package/build/ts/server/clients/storefront/index.js +6 -0
- package/build/ts/server/clients/storefront/index.js.map +1 -0
- package/build/ts/server/clients/storefront/types.d.ts +29 -0
- package/build/ts/server/clients/storefront/types.d.ts.map +1 -0
- package/build/ts/server/clients/storefront/types.js +3 -0
- package/build/ts/server/clients/storefront/types.js.map +1 -0
- package/build/ts/server/clients/types.d.ts +15 -0
- package/build/ts/server/clients/types.d.ts.map +1 -0
- package/build/ts/server/clients/types.js +3 -0
- package/build/ts/server/clients/types.js.map +1 -0
- package/build/ts/server/config-types.d.ts +26 -117
- package/build/ts/server/config-types.d.ts.map +1 -1
- package/build/ts/server/shopify-app.d.ts +3 -3
- package/build/ts/server/shopify-app.d.ts.map +1 -1
- package/build/ts/server/shopify-app.doc.d.ts +4 -0
- package/build/ts/server/shopify-app.doc.d.ts.map +1 -0
- package/build/ts/server/shopify-app.doc.js +36 -0
- package/build/ts/server/shopify-app.doc.js.map +1 -0
- package/build/ts/server/shopify-app.js +6 -4
- package/build/ts/server/shopify-app.js.map +1 -1
- package/build/ts/server/types.d.ts +200 -168
- package/build/ts/server/types.d.ts.map +1 -1
- package/build/ts/server/types.js.map +1 -1
- package/build/ts/server/unauthenticated/admin/factory.d.ts.map +1 -1
- package/build/ts/server/unauthenticated/admin/factory.js +3 -4
- package/build/ts/server/unauthenticated/admin/factory.js.map +1 -1
- package/build/ts/server/unauthenticated/admin/types.d.ts +9 -7
- package/build/ts/server/unauthenticated/admin/types.d.ts.map +1 -1
- package/build/ts/server/unauthenticated/admin/unauthenticated.admin.doc.d.ts +4 -0
- package/build/ts/server/unauthenticated/admin/unauthenticated.admin.doc.d.ts.map +1 -0
- package/build/ts/server/unauthenticated/admin/unauthenticated.admin.doc.js +29 -0
- package/build/ts/server/unauthenticated/admin/unauthenticated.admin.doc.js.map +1 -0
- package/build/ts/server/unauthenticated/helpers/get-offline-session.d.ts +4 -0
- package/build/ts/server/unauthenticated/helpers/get-offline-session.d.ts.map +1 -0
- package/build/ts/server/unauthenticated/helpers/get-offline-session.js +22 -0
- package/build/ts/server/unauthenticated/helpers/get-offline-session.js.map +1 -0
- package/build/ts/server/unauthenticated/helpers/index.d.ts +2 -0
- package/build/ts/server/unauthenticated/helpers/index.d.ts.map +1 -0
- package/build/ts/server/unauthenticated/helpers/index.js +5 -0
- package/build/ts/server/unauthenticated/helpers/index.js.map +1 -0
- package/build/ts/server/unauthenticated/storefront/factory.d.ts +4 -0
- package/build/ts/server/unauthenticated/storefront/factory.d.ts.map +1 -0
- package/build/ts/server/unauthenticated/storefront/factory.js +29 -0
- package/build/ts/server/unauthenticated/storefront/factory.js.map +1 -0
- package/build/ts/server/unauthenticated/storefront/index.d.ts +2 -0
- package/build/ts/server/unauthenticated/storefront/index.d.ts.map +1 -0
- package/build/ts/server/unauthenticated/storefront/index.js +5 -0
- package/build/ts/server/unauthenticated/storefront/index.js.map +1 -0
- package/build/ts/server/unauthenticated/storefront/types.d.ts +34 -0
- package/build/ts/server/unauthenticated/storefront/types.d.ts.map +1 -0
- package/build/ts/server/unauthenticated/storefront/types.js +3 -0
- package/build/ts/server/unauthenticated/storefront/types.js.map +1 -0
- package/build/ts/server/unauthenticated/storefront/unauthenticated.storefront.doc.d.ts +4 -0
- package/build/ts/server/unauthenticated/storefront/unauthenticated.storefront.doc.d.ts.map +1 -0
- package/build/ts/server/unauthenticated/storefront/unauthenticated.storefront.doc.js +29 -0
- package/build/ts/server/unauthenticated/storefront/unauthenticated.storefront.doc.js.map +1 -0
- package/build/ts/server/unauthenticated/types.d.ts +66 -0
- package/build/ts/server/unauthenticated/types.d.ts.map +1 -0
- package/build/ts/server/unauthenticated/types.js +3 -0
- package/build/ts/server/unauthenticated/types.js.map +1 -0
- package/build/ts/server/version.d.ts +1 -1
- package/build/ts/server/version.js +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -4
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RegisterReturn, Shopify, ShopifyRestResources } from '@shopify/shopify-api';
|
|
2
2
|
import { SessionStorage } from '@shopify/shopify-app-session-storage';
|
|
3
3
|
import type { AppConfig, AppConfigArg } from './config-types';
|
|
4
|
-
import type {
|
|
5
|
-
import type { RegisterWebhooksOptions, WebhookContext, WebhookContextWithSession } from './authenticate/webhooks/types';
|
|
6
|
-
import type { UnauthenticatedAdminContext } from './unauthenticated/admin/types';
|
|
4
|
+
import type { AuthenticateWebhook, RegisterWebhooksOptions } from './authenticate/webhooks/types';
|
|
7
5
|
import type { AuthenticatePublic } from './authenticate/public/types';
|
|
6
|
+
import type { AdminContext } from './authenticate/admin/types';
|
|
7
|
+
import type { Unauthenticated } from './unauthenticated/types';
|
|
8
8
|
export interface BasicParams {
|
|
9
9
|
api: Shopify;
|
|
10
10
|
config: AppConfig;
|
|
@@ -33,21 +33,128 @@ export interface LoginError {
|
|
|
33
33
|
type Login = (request: Request) => Promise<LoginError | never>;
|
|
34
34
|
type AddDocumentResponseHeaders = (request: Request, headers: Headers) => void;
|
|
35
35
|
type AuthenticateAdmin<Config extends AppConfigArg, Resources extends ShopifyRestResources = ShopifyRestResources> = (request: Request) => Promise<AdminContext<Config, Resources>>;
|
|
36
|
-
type AuthenticateWebhook<Resources extends ShopifyRestResources = ShopifyRestResources, Topics = string | number | symbol> = (request: Request) => Promise<WebhookContext<Topics> | WebhookContextWithSession<Topics, Resources>>;
|
|
37
|
-
type UnauthenticatedAdmin<Resources extends ShopifyRestResources> = (shop: string) => Promise<UnauthenticatedAdminContext<Resources>>;
|
|
38
36
|
type RestResourcesType<Config extends AppConfigArg> = Config['restResources'] extends ShopifyRestResources ? Config['restResources'] : ShopifyRestResources;
|
|
39
37
|
type SessionStorageType<Config extends AppConfigArg> = Config['sessionStorage'] extends SessionStorage ? Config['sessionStorage'] : SessionStorage;
|
|
40
|
-
|
|
38
|
+
interface Authenticate<Config extends AppConfigArg> {
|
|
39
|
+
/**
|
|
40
|
+
* Authenticate an admin Request and get back an authenticated admin context. Use the authenticated admin context to interact with Shopify.
|
|
41
|
+
*
|
|
42
|
+
* Examples of when to use this are requests from your app's UI, or requests from admin extensions.
|
|
43
|
+
*
|
|
44
|
+
* If there is no session for the Request, this will redirect the merchant to correct auth flows.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* <caption>Authenticating a request for an embedded app.</caption>
|
|
48
|
+
* ```ts
|
|
49
|
+
* // /app/shopify.server.ts
|
|
50
|
+
* import { LATEST_API_VERSION, shopifyApp } from "@shopify/shopify-app-remix/server";
|
|
51
|
+
* import { restResources } from "@shopify/shopify-api/rest/admin/2023-04";
|
|
52
|
+
*
|
|
53
|
+
* const shopify = shopifyApp({
|
|
54
|
+
* restResources,
|
|
55
|
+
* // ...etc
|
|
56
|
+
* });
|
|
57
|
+
* export default shopify;
|
|
58
|
+
* export const authenticate = shopify.authenticate;
|
|
59
|
+
* ```
|
|
60
|
+
* ```ts
|
|
61
|
+
* // /app/routes/**\/*.jsx
|
|
62
|
+
* import { LoaderArgs, json } from "@remix-run/node";
|
|
63
|
+
* import { authenticate } from "../../shopify.server";
|
|
64
|
+
*
|
|
65
|
+
* export async function loader({ request }: LoaderArgs) {
|
|
66
|
+
* const {admin, session, sessionToken, billing} = authenticate.admin(request);
|
|
67
|
+
*
|
|
68
|
+
* return json(await admin.rest.resources.Product.count({ session }));
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
admin: AuthenticateAdmin<Config, RestResourcesType<Config>>;
|
|
41
73
|
/**
|
|
42
|
-
*
|
|
74
|
+
* Authenticate a public request and get back a session token.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* <caption>Authenticating a request from a checkout extension</caption>
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* // /app/routes/api/checkout.jsx
|
|
81
|
+
* import { LoaderArgs, json } from "@remix-run/node";
|
|
82
|
+
* import { authenticate } from "../../shopify.server";
|
|
83
|
+
* import { getWidgets } from "~/db/widgets";
|
|
43
84
|
*
|
|
44
|
-
*
|
|
85
|
+
* export async function loader({ request }: LoaderArgs) {
|
|
86
|
+
* const {sessionToken} = authenticate.public.checkout(request);
|
|
87
|
+
*
|
|
88
|
+
* return json(await getWidgets(sessionToken));
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
public: AuthenticatePublic;
|
|
93
|
+
/**
|
|
94
|
+
* Authenticate a Shopify webhook request, get back an authenticated admin context and details on the webhook request
|
|
45
95
|
*
|
|
46
96
|
* @example
|
|
47
|
-
*
|
|
97
|
+
* <caption>Authenticating a webhook request</caption>
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* // /app/shopify.server.ts
|
|
101
|
+
* import { DeliveryMethod, shopifyApp } from "@shopify/shopify-app-remix/server";
|
|
102
|
+
*
|
|
103
|
+
* const shopify = shopifyApp({
|
|
104
|
+
* webhooks: {
|
|
105
|
+
* APP_UNINSTALLED: {
|
|
106
|
+
* deliveryMethod: DeliveryMethod.Http,
|
|
107
|
+
* callbackUrl: "/webhooks",
|
|
108
|
+
* },
|
|
109
|
+
* },
|
|
110
|
+
* hooks: {
|
|
111
|
+
* afterAuth: async ({ session }) => {
|
|
112
|
+
* shopify.registerWebhooks({ session });
|
|
113
|
+
* },
|
|
114
|
+
* },
|
|
115
|
+
* // ...etc
|
|
116
|
+
* });
|
|
117
|
+
* export default shopify;
|
|
118
|
+
* export const authenticate = shopify.authenticate;
|
|
119
|
+
* ```
|
|
48
120
|
* ```ts
|
|
49
|
-
* // app/
|
|
50
|
-
* import {
|
|
121
|
+
* // /app/routes/webhooks.ts
|
|
122
|
+
* import { ActionArgs } from "@remix-run/node";
|
|
123
|
+
* import { authenticate } from "../shopify.server";
|
|
124
|
+
* import db from "../db.server";
|
|
125
|
+
*
|
|
126
|
+
* export const action = async ({ request }: ActionArgs) => {
|
|
127
|
+
* const { topic, shop, session } = await authenticate.webhook(request);
|
|
128
|
+
*
|
|
129
|
+
* switch (topic) {
|
|
130
|
+
* case "APP_UNINSTALLED":
|
|
131
|
+
* if (session) {
|
|
132
|
+
* await db.session.deleteMany({ where: { shop } });
|
|
133
|
+
* }
|
|
134
|
+
* break;
|
|
135
|
+
* case "CUSTOMERS_DATA_REQUEST":
|
|
136
|
+
* case "CUSTOMERS_REDACT":
|
|
137
|
+
* case "SHOP_REDACT":
|
|
138
|
+
* default:
|
|
139
|
+
* throw new Response("Unhandled webhook topic", { status: 404 });
|
|
140
|
+
* }
|
|
141
|
+
*
|
|
142
|
+
* throw new Response();
|
|
143
|
+
* };
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
webhook: AuthenticateWebhook<RestResourcesType<Config>, keyof Config['webhooks'] | MandatoryTopics>;
|
|
147
|
+
}
|
|
148
|
+
export interface ShopifyAppBase<Config extends AppConfigArg> {
|
|
149
|
+
/**
|
|
150
|
+
* The `SessionStorage` instance you passed in as a config option.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* <caption>Storing sessions with Prisma.</caption>
|
|
154
|
+
* <description>Import the `@shopify/shopify-app-session-storage-prisma` package to store sessions in your Prisma database.</description>
|
|
155
|
+
* ```ts
|
|
156
|
+
* // /app/shopify.server.ts
|
|
157
|
+
* import { shopifyApp } from "@shopify/shopify-app-remix/server";
|
|
51
158
|
* import { PrismaSessionStorage } from "@shopify/shopify-app-session-storage-prisma";
|
|
52
159
|
* import prisma from "~/db.server";
|
|
53
160
|
*
|
|
@@ -66,17 +173,21 @@ export interface ShopifyAppBase<Config extends AppConfigArg> {
|
|
|
66
173
|
* {@link https://shopify.dev/docs/apps/store/security/iframe-protection}
|
|
67
174
|
*
|
|
68
175
|
* @example
|
|
69
|
-
*
|
|
70
|
-
*
|
|
176
|
+
* <caption>Return headers on all requests.</caption>
|
|
177
|
+
* <description>Add headers to all HTML requests by calling `shopify.addDocumentResponseHeaders` in `entry.server.tsx`.</description>
|
|
178
|
+
*
|
|
179
|
+
* ```
|
|
71
180
|
* // ~/shopify.server.ts
|
|
72
|
-
* import { shopifyApp } from "@shopify/shopify-app-remix";
|
|
181
|
+
* import { shopifyApp } from "@shopify/shopify-app-remix/server";
|
|
73
182
|
*
|
|
74
183
|
* const shopify = shopifyApp({
|
|
75
184
|
* // ...etc
|
|
76
185
|
* });
|
|
77
186
|
* export default shopify;
|
|
78
187
|
* export const addDocumentResponseheaders = shopify.addDocumentResponseheaders;
|
|
188
|
+
* ```
|
|
79
189
|
*
|
|
190
|
+
* ```ts
|
|
80
191
|
* // entry.server.tsx
|
|
81
192
|
* import { addDocumentResponseHeaders } from "~/shopify.server";
|
|
82
193
|
*
|
|
@@ -105,9 +216,10 @@ export interface ShopifyAppBase<Config extends AppConfigArg> {
|
|
|
105
216
|
* Register webhook topics for a store using the given session. Most likely you want to use this in combination with the afterAuth hook.
|
|
106
217
|
*
|
|
107
218
|
* @example
|
|
108
|
-
* Registering webhooks
|
|
219
|
+
* <caption>Registering webhooks.</caption>
|
|
220
|
+
* <description>Trigger the registration after a merchant installs your app using the `afterAuth` hook.</description>
|
|
109
221
|
* ```ts
|
|
110
|
-
* import { DeliveryMethod, shopifyApp } from "@shopify/shopify-app-remix";
|
|
222
|
+
* import { DeliveryMethod, shopifyApp } from "@shopify/shopify-app-remix/server";
|
|
111
223
|
*
|
|
112
224
|
* const shopify = shopifyApp({
|
|
113
225
|
* hooks: {
|
|
@@ -129,160 +241,65 @@ export interface ShopifyAppBase<Config extends AppConfigArg> {
|
|
|
129
241
|
/**
|
|
130
242
|
* Ways to authenticate requests from different surfaces across Shopify.
|
|
131
243
|
*
|
|
244
|
+
* @example
|
|
245
|
+
* <caption>Authenticate Shopify requests.</caption>
|
|
246
|
+
* <description>Use the functions in `authenticate` to validate requests coming from Shopify.</description>
|
|
247
|
+
* ```ts
|
|
248
|
+
* // /app/shopify.server.ts
|
|
249
|
+
* import { LATEST_API_VERSION, shopifyApp } from "@shopify/shopify-app-remix/server";
|
|
250
|
+
* import { restResources } from "@shopify/shopify-api/rest/admin/2023-04";
|
|
251
|
+
*
|
|
252
|
+
* const shopify = shopifyApp({
|
|
253
|
+
* restResources,
|
|
254
|
+
* // ...etc
|
|
255
|
+
* });
|
|
256
|
+
* export default shopify;
|
|
257
|
+
* ```
|
|
258
|
+
* ```ts
|
|
259
|
+
* // /app/routes/**\/*.jsx
|
|
260
|
+
* import { LoaderArgs, json } from "@remix-run/node";
|
|
261
|
+
* import shopify from "../../shopify.server";
|
|
262
|
+
*
|
|
263
|
+
* export async function loader({ request }: LoaderArgs) {
|
|
264
|
+
* const {admin, session, sessionToken, billing} = shopify.authenticate.admin(request);
|
|
265
|
+
*
|
|
266
|
+
* return json(await admin.rest.resources.Product.count({ session }));
|
|
267
|
+
* }
|
|
268
|
+
* ```
|
|
132
269
|
*/
|
|
133
|
-
authenticate:
|
|
134
|
-
/**
|
|
135
|
-
* Authenticate an admin Request and get back an authenticated admin context. Use the authenticated admin context to interact with Shopify
|
|
136
|
-
*
|
|
137
|
-
* Examples of when to use this are requests from your app's UI, or requests from admin extensions.
|
|
138
|
-
*
|
|
139
|
-
* If there is no session for the Request, this will redirect the merchant to correct auth flows.
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* Registering webhooks and seeding data when a merchant installs your app.
|
|
143
|
-
* ```ts
|
|
144
|
-
* // app/shopify.server.ts
|
|
145
|
-
* import { LATEST_API_VERSION, shopifyApp } from "@shopify/shopify-app-remix";
|
|
146
|
-
* import { restResources } from "@shopify/shopify-api/rest/admin/2023-04";
|
|
147
|
-
*
|
|
148
|
-
* const shopify = shopifyApp({
|
|
149
|
-
* restResources,
|
|
150
|
-
* // ...etc
|
|
151
|
-
* });
|
|
152
|
-
* export default shopify;
|
|
153
|
-
* export const authenticate = shopify.authenticate;
|
|
154
|
-
*
|
|
155
|
-
* // app/routes/**\/*.jsx
|
|
156
|
-
* import { LoaderArgs, json } from "@remix-run/node";
|
|
157
|
-
* import { authenticate } from "../../shopify.server";
|
|
158
|
-
*
|
|
159
|
-
* export async function loader({ request }: LoaderArgs) {
|
|
160
|
-
* const {admin, session, sessionToken, billing} = authenticate.admin(request);
|
|
161
|
-
*
|
|
162
|
-
* return json(await admin.rest.resources.Product.count({ session }));
|
|
163
|
-
* }
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
admin: AuthenticateAdmin<Config, RestResourcesType<Config>>;
|
|
167
|
-
/**
|
|
168
|
-
* Authenticate a public request and get back a session token
|
|
169
|
-
*
|
|
170
|
-
* An example of when to use this is a request from a checkout extension.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* Authenticating a request from a checkout extension
|
|
174
|
-
*
|
|
175
|
-
* ```ts
|
|
176
|
-
* // app/routes/api/checkout.jsx
|
|
177
|
-
* import { LoaderArgs, json } from "@remix-run/node";
|
|
178
|
-
* import { authenticate } from "../../shopify.server";
|
|
179
|
-
* import { getWidgets } from "~/db/widgets";
|
|
180
|
-
*
|
|
181
|
-
* export async function loader({ request }: LoaderArgs) {
|
|
182
|
-
* const {sessionToken} = authenticate.public(request);
|
|
183
|
-
*
|
|
184
|
-
* return json(await getWidgets(sessionToken));
|
|
185
|
-
* }
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
public: AuthenticatePublic;
|
|
189
|
-
/**
|
|
190
|
-
* Authenticate a Shopify webhook request, get back an authenticated admin context and details on the webhook request
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* Authenticating a webhook request
|
|
194
|
-
*
|
|
195
|
-
* ```ts
|
|
196
|
-
* // app/routes/api/checkout.jsx
|
|
197
|
-
* import {
|
|
198
|
-
* DeliveryMethod,
|
|
199
|
-
* shopifyApp,
|
|
200
|
-
* } from "@shopify/shopify-app-remix";
|
|
201
|
-
*
|
|
202
|
-
* const shopify = shopifyApp({
|
|
203
|
-
* webhooks: {
|
|
204
|
-
* APP_UNINSTALLED: {
|
|
205
|
-
* deliveryMethod: DeliveryMethod.Http,
|
|
206
|
-
* callbackUrl: "/webhooks",
|
|
207
|
-
* },
|
|
208
|
-
* },
|
|
209
|
-
* hooks: {
|
|
210
|
-
* afterAuth: async ({ session }) => {
|
|
211
|
-
* shopify.registerWebhooks({ session });
|
|
212
|
-
* },
|
|
213
|
-
* },
|
|
214
|
-
* // ...etc
|
|
215
|
-
* });
|
|
216
|
-
* export default shopify;
|
|
217
|
-
* export const authenticate = shopify.authenticate;
|
|
218
|
-
*
|
|
219
|
-
* // app/routes/webhooks.ts
|
|
220
|
-
* import { ActionArgs } from "@remix-run/node";
|
|
221
|
-
* import { authenticate } from "../shopify.server";
|
|
222
|
-
* import db from "../db.server";
|
|
223
|
-
*
|
|
224
|
-
* export const action = async ({ request }: ActionArgs) => {
|
|
225
|
-
* const { topic, shop, session } = await authenticate.webhook(request);
|
|
226
|
-
*
|
|
227
|
-
* switch (topic) {
|
|
228
|
-
* case "APP_UNINSTALLED":
|
|
229
|
-
* if (session) {
|
|
230
|
-
* await db.session.deleteMany({ where: { shop } });
|
|
231
|
-
* }
|
|
232
|
-
* break;
|
|
233
|
-
* case "CUSTOMERS_DATA_REQUEST":
|
|
234
|
-
* case "CUSTOMERS_REDACT":
|
|
235
|
-
* case "SHOP_REDACT":
|
|
236
|
-
* default:
|
|
237
|
-
* throw new Response("Unhandled webhook topic", { status: 404 });
|
|
238
|
-
* }
|
|
239
|
-
*
|
|
240
|
-
* throw new Response();
|
|
241
|
-
* };
|
|
242
|
-
* ```
|
|
243
|
-
*/
|
|
244
|
-
webhook: AuthenticateWebhook<RestResourcesType<Config>, keyof Config['webhooks'] | MandatoryTopics>;
|
|
245
|
-
};
|
|
270
|
+
authenticate: Authenticate<Config>;
|
|
246
271
|
/**
|
|
247
|
-
*
|
|
272
|
+
* Ways to get Contexts from requests that do not originate from Shopify.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* <caption>Using unauthenticated contexts.</caption>
|
|
276
|
+
* <description>Create contexts for requests that don't come from Shopify.</description>
|
|
277
|
+
* ```ts
|
|
278
|
+
* // /app/shopify.server.ts
|
|
279
|
+
* import { LATEST_API_VERSION, shopifyApp } from "@shopify/shopify-app-remix/server";
|
|
280
|
+
* import { restResources } from "@shopify/shopify-api/rest/admin/2023-04";
|
|
281
|
+
*
|
|
282
|
+
* const shopify = shopifyApp({
|
|
283
|
+
* restResources,
|
|
284
|
+
* // ...etc
|
|
285
|
+
* });
|
|
286
|
+
* export default shopify;
|
|
287
|
+
* ```
|
|
288
|
+
* ```ts
|
|
289
|
+
* // /app/routes/**\/*.jsx
|
|
290
|
+
* import { LoaderArgs, json } from "@remix-run/node";
|
|
291
|
+
* import { authenticateExternal } from "~/helpers/authenticate"
|
|
292
|
+
* import shopify from "../../shopify.server";
|
|
293
|
+
*
|
|
294
|
+
* export async function loader({ request }: LoaderArgs) {
|
|
295
|
+
* const shop = await authenticateExternal(request)
|
|
296
|
+
* const {admin} = await shopify.unauthenticated.admin(shop);
|
|
248
297
|
*
|
|
298
|
+
* return json(await admin.rest.resources.Product.count({ session }));
|
|
299
|
+
* }
|
|
300
|
+
* ```
|
|
249
301
|
*/
|
|
250
|
-
unauthenticated:
|
|
251
|
-
/**
|
|
252
|
-
* Get an admin context by passing a shop
|
|
253
|
-
*
|
|
254
|
-
* **Warning** This should only be used for Requests that do not originate from Shopify.
|
|
255
|
-
* You must do your own authentication before using this method.
|
|
256
|
-
* This method throws an error if there is no session for the shop.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* Responding to a request from an external service not controlled by Shopify.
|
|
260
|
-
* ```ts
|
|
261
|
-
* // app/shopify.server.ts
|
|
262
|
-
* import { LATEST_API_VERSION, shopifyApp } from "@shopify/shopify-app-remix";
|
|
263
|
-
* import { restResources } from "@shopify/shopify-api/rest/admin/2023-04";
|
|
264
|
-
*
|
|
265
|
-
* const shopify = shopifyApp({
|
|
266
|
-
* restResources,
|
|
267
|
-
* // ...etc
|
|
268
|
-
* });
|
|
269
|
-
* export default shopify;
|
|
270
|
-
*
|
|
271
|
-
* // app/routes/**\/*.jsx
|
|
272
|
-
* import { LoaderArgs, json } from "@remix-run/node";
|
|
273
|
-
* import { authenticateExternal } from "~/helpers/authenticate"
|
|
274
|
-
* import shopify from "../../shopify.server";
|
|
275
|
-
*
|
|
276
|
-
* export async function loader({ request }: LoaderArgs) {
|
|
277
|
-
* const shop = await authenticateExternal(request)
|
|
278
|
-
* const {admin} = await shopify.unauthenticated.admin(shop);
|
|
279
|
-
*
|
|
280
|
-
* return json(await admin.rest.resources.Product.count({ session }));
|
|
281
|
-
* }
|
|
282
|
-
* ```
|
|
283
|
-
*/
|
|
284
|
-
admin: UnauthenticatedAdmin<RestResourcesType<Config>>;
|
|
285
|
-
};
|
|
302
|
+
unauthenticated: Unauthenticated<RestResourcesType<Config>>;
|
|
286
303
|
}
|
|
287
304
|
interface ShopifyAppLogin {
|
|
288
305
|
/**
|
|
@@ -293,7 +310,21 @@ interface ShopifyAppLogin {
|
|
|
293
310
|
* because Admin apps aren't allowed to show a login page.
|
|
294
311
|
*
|
|
295
312
|
* @example
|
|
296
|
-
*
|
|
313
|
+
* <caption>Creating a login page.</caption>
|
|
314
|
+
* <description>Use `shopify.login` to create a login form, in a route that can handle GET and POST requests.</description>
|
|
315
|
+
* ```ts
|
|
316
|
+
* // /app/shopify.server.ts
|
|
317
|
+
* import { LATEST_API_VERSION, shopifyApp } from "@shopify/shopify-app-remix/server";
|
|
318
|
+
*
|
|
319
|
+
* const shopify = shopifyApp({
|
|
320
|
+
* // ...etc
|
|
321
|
+
* });
|
|
322
|
+
* export default shopify;
|
|
323
|
+
* ```
|
|
324
|
+
* ```ts
|
|
325
|
+
* // /app/routes/auth/login.tsx
|
|
326
|
+
* import shopify from "../../shopify.server";
|
|
327
|
+
*
|
|
297
328
|
* export async function loader({ request }: LoaderArgs) {
|
|
298
329
|
* const errors = shopify.login(request);
|
|
299
330
|
*
|
|
@@ -337,6 +368,7 @@ interface ShopifyAppLogin {
|
|
|
337
368
|
* </Page>
|
|
338
369
|
* );
|
|
339
370
|
* }
|
|
371
|
+
* ```
|
|
340
372
|
*/
|
|
341
373
|
login: Login;
|
|
342
374
|
}
|
|
@@ -346,7 +378,7 @@ export type AppStoreApp<Config extends AppConfigArg> = ShopifyAppBase<Config> &
|
|
|
346
378
|
/**
|
|
347
379
|
* An object your app can use to interact with Shopify.
|
|
348
380
|
*
|
|
349
|
-
* By default, the app's distribution
|
|
381
|
+
* By default, the app's distribution is `AppStore`.
|
|
350
382
|
*/
|
|
351
383
|
export type ShopifyApp<Config extends AppConfigArg> = Config['distribution'] extends AppDistribution.ShopifyAdmin ? AdminApp<Config> : Config['distribution'] extends AppDistribution.SingleMerchant ? SingleMerchantApp<Config> : Config['distribution'] extends AppDistribution.AppStore ? AppStoreApp<Config> : AppStoreApp<Config>;
|
|
352
384
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,OAAO,EACP,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAC,cAAc,EAAC,MAAM,sCAAsC,CAAC;AAEpE,OAAO,KAAK,EAAC,SAAS,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,OAAO,EACP,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAC,cAAc,EAAC,MAAM,sCAAsC,CAAC;AAEpE,OAAO,KAAK,EAAC,SAAS,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAE7D,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC3B;AAED,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,UAAU,GACV,SAAS,CAAC;AAId,oBAAY,eAAe;IACzB,QAAQ,cAAc;IACtB,cAAc,oBAAoB;IAClC,YAAY,kBAAkB;CAC/B;AAED,MAAM,MAAM,eAAe,GACvB,wBAAwB,GACxB,kBAAkB,GAClB,aAAa,CAAC;AAElB,UAAU,UAAU;IAClB,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxB;AAED,UAAU,SAAU,SAAQ,KAAK,CAAC,SAAS,CAAC;CAAG;AAE/C,KAAK,gBAAgB,GAAG,CACtB,OAAO,EAAE,uBAAuB,KAC7B,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B,oBAAY,cAAc;IACxB,WAAW,iBAAiB;IAC5B,WAAW,iBAAiB;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB;AAED,KAAK,KAAK,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;AAE/D,KAAK,0BAA0B,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;AAE/E,KAAK,iBAAiB,CACpB,MAAM,SAAS,YAAY,EAC3B,SAAS,SAAS,oBAAoB,GAAG,oBAAoB,IAC3D,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAEnE,KAAK,iBAAiB,CAAC,MAAM,SAAS,YAAY,IAChD,MAAM,CAAC,eAAe,CAAC,SAAS,oBAAoB,GAChD,MAAM,CAAC,eAAe,CAAC,GACvB,oBAAoB,CAAC;AAE3B,KAAK,kBAAkB,CAAC,MAAM,SAAS,YAAY,IACjD,MAAM,CAAC,gBAAgB,CAAC,SAAS,cAAc,GAC3C,MAAM,CAAC,gBAAgB,CAAC,GACxB,cAAc,CAAC;AAErB,UAAU,YAAY,CAAC,MAAM,SAAS,YAAY;IAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,KAAK,EAAE,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5D;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,EAAE,kBAAkB,CAAC;IAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoDG;IACH,OAAO,EAAE,mBAAmB,CAC1B,iBAAiB,CAAC,MAAM,CAAC,EACzB,MAAM,MAAM,CAAC,UAAU,CAAC,GAAG,eAAe,CAC3C,CAAC;CACH;AAED,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,YAAY;IACzD;;;;;;;;;;;;;;;;;;;OAmBG;IACH,cAAc,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACH,0BAA0B,EAAE,0BAA0B,CAAC;IAEvD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,eAAe,EAAE,eAAe,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;CAC7D;AAED,UAAU,eAAe;IACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmEG;IACH,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,MAAM,QAAQ,CAAC,MAAM,SAAS,YAAY,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;AAC3E,MAAM,MAAM,iBAAiB,CAAC,MAAM,SAAS,YAAY,IACvD,cAAc,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC;AAC3C,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,YAAY,IAAI,cAAc,CAAC,MAAM,CAAC,GAC3E,eAAe,CAAC;AAElB;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,YAAY,IAChD,MAAM,CAAC,cAAc,CAAC,SAAS,eAAe,CAAC,YAAY,GACvD,QAAQ,CAAC,MAAM,CAAC,GAChB,MAAM,CAAC,cAAc,CAAC,SAAS,eAAe,CAAC,cAAc,GAC7D,iBAAiB,CAAC,MAAM,CAAC,GACzB,MAAM,CAAC,cAAc,CAAC,SAAS,eAAe,CAAC,QAAQ,GACvD,WAAW,CAAC,MAAM,CAAC,GACnB,WAAW,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/server/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/server/types.ts"],"names":[],"mappings":";;;AA8BA,+CAA+C;AAC/C,sFAAsF;AACtF,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,yCAAsB,CAAA;IACtB,qDAAkC,CAAA;IAClC,iDAA8B,CAAA;AAChC,CAAC,EAJW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAI1B;AAiBD,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,8CAA4B,CAAA;IAC5B,8CAA4B,CAAA;AAC9B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/admin/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/admin/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AAIxC,OAAO,EAAC,2BAA2B,EAAC,MAAM,SAAS,CAAC;AAEpD,wBAAgB,kCAAkC,CAChD,SAAS,SAAS,oBAAoB,EACtC,MAAM,EAAE,WAAW,UAEX,MAAM,KACX,QAAQ,4BAA4B,SAAS,CAAC,CAAC,CAcnD"}
|
|
@@ -4,15 +4,14 @@ exports.unauthenticatedAdminContextFactory = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var shopify_api_1 = require("@shopify/shopify-api");
|
|
6
6
|
var admin_1 = require("../../clients/admin");
|
|
7
|
+
var helpers_1 = require("../helpers");
|
|
7
8
|
function unauthenticatedAdminContextFactory(params) {
|
|
8
9
|
var _this = this;
|
|
9
10
|
return function (shop) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
10
|
-
var
|
|
11
|
+
var session;
|
|
11
12
|
return tslib_1.__generator(this, function (_a) {
|
|
12
13
|
switch (_a.label) {
|
|
13
|
-
case 0:
|
|
14
|
-
offlineSessionId = params.api.session.getOfflineId(shop);
|
|
15
|
-
return [4 /*yield*/, params.config.sessionStorage.loadSession(offlineSessionId)];
|
|
14
|
+
case 0: return [4 /*yield*/, (0, helpers_1.getOfflineSession)(shop, params)];
|
|
16
15
|
case 1:
|
|
17
16
|
session = _a.sent();
|
|
18
17
|
if (!session) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/admin/factory.ts"],"names":[],"mappings":";;;;AAAA,oDAAwE;AAGxE,6CAAuD;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/admin/factory.ts"],"names":[],"mappings":";;;;AAAA,oDAAwE;AAGxE,6CAAuD;AACvD,sCAA6C;AAI7C,SAAgB,kCAAkC,CAEhD,MAAmB;IAFrB,iBAmBC;IAhBC,OAAO,UACL,IAAY;;;;wBAEI,qBAAM,IAAA,2BAAiB,EAAC,IAAI,EAAE,MAAM,CAAC,EAAA;;oBAA/C,OAAO,GAAG,SAAqC;oBAErD,IAAI,CAAC,OAAO,EAAE;wBACZ,MAAM,IAAI,0BAAY,CACpB,4CAAqC,IAAI,iDAA8C,CACxF,CAAC;qBACH;oBAED,sBAAO;4BACL,OAAO,SAAA;4BACP,KAAK,EAAE,IAAA,0BAAkB,EAAY,EAAC,MAAM,QAAA,EAAE,OAAO,SAAA,EAAC,CAAC;yBACxD,EAAC;;;SACH,CAAC;AACJ,CAAC;AAnBD,gFAmBC"}
|
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import { Session, ShopifyRestResources } from '@shopify/shopify-api';
|
|
2
|
-
import
|
|
2
|
+
import { AdminApiContext } from '../../clients';
|
|
3
3
|
export interface UnauthenticatedAdminContext<Resources extends ShopifyRestResources> {
|
|
4
4
|
/**
|
|
5
5
|
* The session for the given shop.
|
|
6
6
|
*
|
|
7
7
|
* This comes from the session storage which `shopifyApp` uses to store sessions in your database of choice.
|
|
8
8
|
*
|
|
9
|
-
* This will always be an offline session. You can use to get shop
|
|
9
|
+
* This will always be an offline session. You can use to get shop-specific data.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
*
|
|
12
|
+
* <caption>Using the offline session.</caption>
|
|
13
|
+
* <description>Get your app's shop-specific data using the returned offline `session` object.</description>
|
|
13
14
|
* ```ts
|
|
14
|
-
* // app/routes
|
|
15
|
+
* // /app/routes/**\/*.ts
|
|
15
16
|
* import { LoaderArgs, json } from "@remix-run/node";
|
|
16
17
|
* import { unauthenticated } from "../shopify.server";
|
|
17
|
-
* import {
|
|
18
|
+
* import { getMyAppData } from "~/db/model.server";
|
|
18
19
|
*
|
|
19
20
|
* export const loader = async ({ request }: LoaderArgs) => {
|
|
20
21
|
* const shop = getShopFromExternalRequest(request);
|
|
21
22
|
* const { session } = await unauthenticated.admin(shop);
|
|
22
|
-
* return json(await
|
|
23
|
+
* return json(await getMyAppData({shop: session.shop));
|
|
23
24
|
* };
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
session: Session;
|
|
27
28
|
/**
|
|
28
|
-
* Methods for interacting with the
|
|
29
|
+
* Methods for interacting with the GraphQL / REST Admin APIs for the given store.
|
|
29
30
|
*/
|
|
30
31
|
admin: AdminApiContext<Resources>;
|
|
31
32
|
}
|
|
33
|
+
export type GetUnauthenticatedAdminContext<Resources extends ShopifyRestResources> = (shop: string) => Promise<UnauthenticatedAdminContext<Resources>>;
|
|
32
34
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/admin/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAEnE,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/admin/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,2BAA2B,CAC1C,SAAS,SAAS,oBAAoB;IAEtC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,8BAA8B,CACxC,SAAS,SAAS,oBAAoB,IACpC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unauthenticated.admin.doc.d.ts","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/admin/unauthenticated.admin.doc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,6BAA6B,EAAC,MAAM,wBAAwB,CAAC;AAErE,QAAA,MAAM,IAAI,EAAE,6BAyBX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var data = {
|
|
4
|
+
name: 'Unauthenticated admin',
|
|
5
|
+
description: "Allows interacting with the Admin API on requests that didn't come from Shopify." +
|
|
6
|
+
'\n\n> Caution: This should only be used for Requests that do not originate from Shopify.' +
|
|
7
|
+
'\n> You must do your own authentication before using this method.' +
|
|
8
|
+
"\n>This function doesn't perform **any** validation and shouldn't rely on unvalidated user input.",
|
|
9
|
+
category: 'Unauthenticated',
|
|
10
|
+
type: 'object',
|
|
11
|
+
isVisualComponent: false,
|
|
12
|
+
definitions: [
|
|
13
|
+
{
|
|
14
|
+
title: 'unauthenticated.admin',
|
|
15
|
+
description: 'Creates an unauthenticated Admin context.',
|
|
16
|
+
type: 'GetUnauthenticatedAdminContext',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
jsDocTypeExamples: ['UnauthenticatedAdminContext', 'AdminApiContext'],
|
|
20
|
+
related: [
|
|
21
|
+
{
|
|
22
|
+
name: 'API context',
|
|
23
|
+
subtitle: 'Interact with the Admin API.',
|
|
24
|
+
url: '/docs/api/shopify-app-remix/apis/admin-api',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
exports.default = data;
|
|
29
|
+
//# sourceMappingURL=unauthenticated.admin.doc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unauthenticated.admin.doc.js","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/admin/unauthenticated.admin.doc.ts"],"names":[],"mappings":";;AAEA,IAAM,IAAI,GAAkC;IAC1C,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EACT,kFAAkF;QAClF,0FAA0F;QAC1F,mEAAmE;QACnE,mGAAmG;IACrG,QAAQ,EAAE,iBAAiB;IAC3B,IAAI,EAAE,QAAQ;IACd,iBAAiB,EAAE,KAAK;IACxB,WAAW,EAAE;QACX;YACE,KAAK,EAAE,uBAAuB;YAC9B,WAAW,EAAE,2CAA2C;YACxD,IAAI,EAAE,gCAAgC;SACvC;KACF;IACD,iBAAiB,EAAE,CAAC,6BAA6B,EAAE,iBAAiB,CAAC;IACrE,OAAO,EAAE;QACP;YACE,IAAI,EAAE,aAAa;YACnB,QAAQ,EAAE,8BAA8B;YACxC,GAAG,EAAE,4CAA4C;SAClD;KACF;CACF,CAAC;AAEF,kBAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-offline-session.d.ts","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/helpers/get-offline-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAE7C,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,EAAC,GAAG,EAAE,MAAM,EAAC,EAAE,WAAW,GACzB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAK9B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOfflineSession = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
function getOfflineSession(shop, _a) {
|
|
6
|
+
var api = _a.api, config = _a.config;
|
|
7
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
8
|
+
var offlineSessionId, session;
|
|
9
|
+
return tslib_1.__generator(this, function (_b) {
|
|
10
|
+
switch (_b.label) {
|
|
11
|
+
case 0:
|
|
12
|
+
offlineSessionId = api.session.getOfflineId(shop);
|
|
13
|
+
return [4 /*yield*/, config.sessionStorage.loadSession(offlineSessionId)];
|
|
14
|
+
case 1:
|
|
15
|
+
session = _b.sent();
|
|
16
|
+
return [2 /*return*/, session];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.getOfflineSession = getOfflineSession;
|
|
22
|
+
//# sourceMappingURL=get-offline-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-offline-session.js","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/helpers/get-offline-session.ts"],"names":[],"mappings":";;;;AAGA,SAAsB,iBAAiB,CACrC,IAAY,EACZ,EAA0B;QAAzB,GAAG,SAAA,EAAE,MAAM,YAAA;;;;;;oBAEN,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;oBACxC,qBAAM,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAA;;oBAAnE,OAAO,GAAG,SAAyD;oBAEzE,sBAAO,OAAO,EAAC;;;;CAChB;AARD,8CAQC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/server/unauthenticated/helpers/index.ts"],"names":[],"mappings":";;;AAAA,gEAAsC"}
|