@agnostack/next-shopify 1.0.0 → 1.1.0-alpha.1
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/CHANGELOG.md +15 -0
- package/dist/handlers/appUninstalledHandler.d.ts +1 -0
- package/dist/handlers/appUninstalledHandler.js +18 -0
- package/dist/handlers/appUninstalledHandler.js.map +1 -0
- package/dist/handlers/authCallbackHandler.d.ts +9 -0
- package/dist/handlers/authCallbackHandler.js +59 -0
- package/dist/handlers/authCallbackHandler.js.map +1 -0
- package/dist/handlers/authHandler.d.ts +9 -0
- package/dist/handlers/authHandler.js +31 -0
- package/dist/handlers/authHandler.js.map +1 -0
- package/dist/handlers/index.d.ts +3 -0
- package/dist/handlers/index.js +16 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +3 -12
- package/dist/index.js.map +1 -1
- package/dist/protectRoute.d.ts +15 -0
- package/dist/protectRoute.js +45 -0
- package/dist/protectRoute.js.map +1 -0
- package/dist/utils/display.d.ts +2 -9
- package/dist/utils/display.js +9 -37
- package/dist/utils/display.js.map +1 -1
- package/dist/utils/firebase.d.ts +15 -0
- package/dist/utils/firebase.js +94 -0
- package/dist/utils/firebase.js.map +1 -0
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/shopify.d.ts +69 -0
- package/dist/utils/shopify.js +93 -0
- package/dist/utils/shopify.js.map +1 -0
- package/dist/withShopify.d.ts +4 -0
- package/dist/withShopify.js +150 -0
- package/dist/withShopify.js.map +1 -0
- package/package.json +7 -7
- package/dist/utils/data.d.ts +0 -70
- package/dist/utils/data.js +0 -270
- package/dist/utils/data.js.map +0 -1
- package/dist/utils/locations.d.ts +0 -20
- package/dist/utils/locations.js +0 -26
- package/dist/utils/locations.js.map +0 -1
- package/dist/withPlugins.d.ts +0 -6
- package/dist/withPlugins.js +0 -38
- package/dist/withPlugins.js.map +0 -1
- package/dist/withZendeskCLI.d.ts +0 -4
- package/dist/withZendeskCLI.js +0 -154
- package/dist/withZendeskCLI.js.map +0 -1
- package/dist/zendeskCLIHandler.d.ts +0 -1
- package/dist/zendeskCLIHandler.js +0 -109
- package/dist/zendeskCLIHandler.js.map +0 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getRedirectUrl = exports.registerWebhooks = exports.getInitializedShopify = exports.API_ROUTE_NAMES = exports.PAGE_ROUTE_NAMES = void 0;
|
|
7
|
+
const cookies_1 = __importDefault(require("cookies"));
|
|
8
|
+
const shopify_api_1 = require("@shopify/shopify-api");
|
|
9
|
+
const display_1 = require("./display");
|
|
10
|
+
const firebase_1 = require("./firebase");
|
|
11
|
+
exports.PAGE_ROUTE_NAMES = {
|
|
12
|
+
EXIT: 'pageRouteExit',
|
|
13
|
+
ERROR: 'pageRouteError',
|
|
14
|
+
};
|
|
15
|
+
exports.API_ROUTE_NAMES = {
|
|
16
|
+
AUTH: 'apiRouteAuth',
|
|
17
|
+
AUTH_CALLBACK: 'apiRouteAuthCallback',
|
|
18
|
+
APP_UNINSTALLED: 'apiRouteAppUninstalled',
|
|
19
|
+
};
|
|
20
|
+
const getInitializedShopify = (props, _shop) => {
|
|
21
|
+
const { FB_CONFIG, FB_ROOT_COLLECTION, APP_ID, APP_CONFIG } = props;
|
|
22
|
+
const shop = shopify_api_1.Shopify.Utils.sanitizeShop(_shop);
|
|
23
|
+
const sessionHandler = new firebase_1.FirebaseSessionHandler(FB_CONFIG, {
|
|
24
|
+
shop,
|
|
25
|
+
app: APP_ID,
|
|
26
|
+
collection: FB_ROOT_COLLECTION,
|
|
27
|
+
});
|
|
28
|
+
shopify_api_1.Shopify.Context.initialize(Object.assign(Object.assign({}, APP_CONFIG), { SESSION_STORAGE: new shopify_api_1.Shopify.Session.CustomSessionStorage((session) => firebase_1.storeCallback(session, sessionHandler), (id) => firebase_1.loadCallback(id, sessionHandler), (id) => firebase_1.deleteSessionsCallback(id, sessionHandler), (ids) => firebase_1.deleteSessionsCallback(ids, sessionHandler), (__shop) => firebase_1.findSessionsByShop(shopify_api_1.Shopify.Utils.sanitizeShop(__shop), sessionHandler)) }));
|
|
29
|
+
return shopify_api_1.Shopify;
|
|
30
|
+
};
|
|
31
|
+
exports.getInitializedShopify = getInitializedShopify;
|
|
32
|
+
const registerTopicWebhook = async (props, webhook, topic, { accessToken, shop }) => {
|
|
33
|
+
const shopify = exports.getInitializedShopify(props, shop);
|
|
34
|
+
const webhookResponse = await shopify.Webhooks.Registry.register(Object.assign(Object.assign({ topic }, webhook), { accessToken,
|
|
35
|
+
shop }));
|
|
36
|
+
if (!webhookResponse[topic].success) {
|
|
37
|
+
throw new Error(`Failed to register ${webhook.path} on topic: ${topic} webhook`, webhookResponse.result);
|
|
38
|
+
}
|
|
39
|
+
return webhookResponse[topic].success;
|
|
40
|
+
};
|
|
41
|
+
const registerWebhooks = async (props, webhookRegistry, session) => (Promise.all(Object.entries(webhookRegistry).map(async ([topic, webhooks]) => (Promise.all(webhooks.map(async (webhook) => registerTopicWebhook(props, webhook, topic, session)))))));
|
|
42
|
+
exports.registerWebhooks = registerWebhooks;
|
|
43
|
+
// NOTE this is a custom implementation of the @shopify/shopify-api beginAuth method... see NOTE below
|
|
44
|
+
const beginAuth = (props, { req, res, shop: _shop, isOnline = true, }) => {
|
|
45
|
+
const { APP_CONFIG, APP_CALLBACK_URI, APP_STATE_COOKIE_NAME, SHOPIFY_API_PUBLIC_KEY, SHOPIFY_API_SCOPES, } = props;
|
|
46
|
+
// redirectPath,
|
|
47
|
+
// isOnline = true,
|
|
48
|
+
const shop = shopify_api_1.Shopify.Utils.sanitizeShop(_shop);
|
|
49
|
+
const state = `${isOnline ? 'online' : 'offline'}_${display_1.getGUID()}`;
|
|
50
|
+
const cookies = new cookies_1.default(req, res, {
|
|
51
|
+
keys: [APP_CONFIG.API_SECRET_KEY],
|
|
52
|
+
secure: true,
|
|
53
|
+
});
|
|
54
|
+
// NOTE modified sameSite from 'lax' to 'none' is the major change from the @shopify/shopify-api version
|
|
55
|
+
cookies.set(APP_STATE_COOKIE_NAME, state, {
|
|
56
|
+
signed: true,
|
|
57
|
+
expires: new Date(Date.now() + 60000),
|
|
58
|
+
sameSite: 'none',
|
|
59
|
+
secure: true,
|
|
60
|
+
});
|
|
61
|
+
// TODO: explore objectToQuerystring
|
|
62
|
+
const queryParams = new URLSearchParams({
|
|
63
|
+
client_id: SHOPIFY_API_PUBLIC_KEY,
|
|
64
|
+
scope: SHOPIFY_API_SCOPES,
|
|
65
|
+
redirect_uri: APP_CALLBACK_URI,
|
|
66
|
+
state,
|
|
67
|
+
'grant_options[]': isOnline ? 'per-user' : '',
|
|
68
|
+
}).toString();
|
|
69
|
+
return `https://${shop}/admin/oauth/authorize?${queryParams}`;
|
|
70
|
+
};
|
|
71
|
+
const getRedirectUrl = (props, { req, res, query, shop: _shop, }) => {
|
|
72
|
+
// const { APP_CALLBACK_URI, APP_CALLBACK_ROUTE, PAGE_PATHS } = props
|
|
73
|
+
const { APP_CALLBACK_URI, PAGE_PATHS } = props;
|
|
74
|
+
const shop = shopify_api_1.Shopify.Utils.sanitizeShop(_shop);
|
|
75
|
+
const { embedded, host } = query !== null && query !== void 0 ? query : {};
|
|
76
|
+
if (!shop) {
|
|
77
|
+
return `${PAGE_PATHS[exports.PAGE_ROUTE_NAMES.ERROR]}?code=no_shop_provided`;
|
|
78
|
+
}
|
|
79
|
+
if (embedded === '1') {
|
|
80
|
+
// TODO: explore objectToQuerystring
|
|
81
|
+
const redirectUriParams = new URLSearchParams({
|
|
82
|
+
shop,
|
|
83
|
+
host,
|
|
84
|
+
}).toString();
|
|
85
|
+
// TODO: explore objectToQuerystring
|
|
86
|
+
const queryParams = new URLSearchParams(Object.assign(Object.assign({}, query), { shop, redirectUri: `${APP_CALLBACK_URI}?${redirectUriParams}` })).toString();
|
|
87
|
+
return `${PAGE_PATHS[exports.PAGE_ROUTE_NAMES.EXIT]}?${queryParams}`;
|
|
88
|
+
}
|
|
89
|
+
// return Shopify.Auth.beginAuth( // see NOTE above beginAuth
|
|
90
|
+
return beginAuth(props, { req, res, shop });
|
|
91
|
+
};
|
|
92
|
+
exports.getRedirectUrl = getRedirectUrl;
|
|
93
|
+
//# sourceMappingURL=shopify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shopify.js","sourceRoot":"","sources":["../../src/utils/shopify.js"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAC7B,sDAA8C;AAE9C,uCAAmC;AACnC,yCAMmB;AAEN,QAAA,gBAAgB,GAAG;IAC9B,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,gBAAgB;CACxB,CAAA;AAEY,QAAA,eAAe,GAAG;IAC7B,IAAI,EAAE,cAAc;IACpB,aAAa,EAAE,sBAAsB;IACrC,eAAe,EAAE,wBAAwB;CAC1C,CAAA;AAEM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;IACpD,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;IACnE,MAAM,IAAI,GAAG,qBAAO,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;IAC9C,MAAM,cAAc,GAAG,IAAI,iCAAsB,CAAC,SAAS,EAAE;QAC3D,IAAI;QACJ,GAAG,EAAE,MAAM;QACX,UAAU,EAAE,kBAAkB;KAC/B,CAAC,CAAA;IAEF,qBAAO,CAAC,OAAO,CAAC,UAAU,iCACrB,UAAU,KACb,eAAe,EAAE,IAAI,qBAAO,CAAC,OAAO,CAAC,oBAAoB,CACvD,CAAC,OAAO,EAAE,EAAE,CAAC,w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Ac,kBAqC1B"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.withShopify = void 0;
|
|
15
|
+
// import chalk from 'chalk'
|
|
16
|
+
const constants_1 = require("next/constants");
|
|
17
|
+
const next_plugins_1 = require("@agnostack/next-plugins");
|
|
18
|
+
const utils_1 = require("./utils");
|
|
19
|
+
// TODO!!!!!!: add middleware export for headers???
|
|
20
|
+
const withShopify = async (nextPhase, _a) => {
|
|
21
|
+
var { nextConfig } = _a, config = __rest(_a, ["nextConfig"]);
|
|
22
|
+
const _b = nextConfig !== null && nextConfig !== void 0 ? nextConfig : {}, { basePath: _basePath, headers: _headers, serverRuntimeConfig: _serverRuntimeConfig = {} } = _b, _nextConfig = __rest(_b, ["basePath", "headers", "serverRuntimeConfig"]);
|
|
23
|
+
const _c = config !== null && config !== void 0 ? config : {}, {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
|
+
defaultConfig } = _c, // NOTE: This is here in case we need anything from it
|
|
26
|
+
pluginConfig = __rest(_c, ["defaultConfig"]);
|
|
27
|
+
const basePath = utils_1.ensureString(_basePath);
|
|
28
|
+
const { interactive, pageRoutes: { [utils_1.PAGE_ROUTE_NAMES.EXIT]: _pageRouteExit = '/exit', [utils_1.PAGE_ROUTE_NAMES.ERROR]: _pageRouteError = '/error', }, apiRoutes: { [utils_1.API_ROUTE_NAMES.AUTH]: _apiRouteAuth = '/api/auth', [utils_1.API_ROUTE_NAMES.AUTH_CALLBACK]: _apiRouteAuthCallback = '/api/auth/callback', [utils_1.API_ROUTE_NAMES.APP_UNINSTALLED]: _apiRouteAppUninstalled = '/api/webhooks/app/uninstalled', } = {}, params: { APP_ID, APP_STATE_COOKIE_NAME = 'shopify_app_state', NEXT_PUBLIC_APP_BASE_URL: APP_URL, NEXT_PUBLIC_APP_ROUTE_PAGE_EXIT: _pageRouteParamExit, NEXT_PUBLIC_APP_ROUTE_PAGE_ERROR: _pageRouteParamError, NEXT_PUBLIC_APP_ROUTE_API_AUTH: _apiRouteParamAuth, NEXT_PUBLIC_APP_ROUTE_API_AUTH_CALLBACK: _apiRouteParamAuthCallback, NEXT_PUBLIC_APP_ROUTE_API_UNINSTALLED: _apiRouteParamAppUninstalled, NEXT_PUBLIC_SHOPIFY_API_KEY: SHOPIFY_API_PUBLIC_KEY, NEXT_PUBLIC_FB_PROJECT_ID: FB_PROJECT_ID, NEXT_PUBLIC_FB_ROOT_COLLECTION: FB_ROOT_COLLECTION, NEXT_PUBLIC_FB_APP_ID, FB_API_KEY, SHOPIFY_API_KEY, SHOPIFY_API_SCOPES, SHOPIFY_API_VERSION = '2021-04', } = {}, } = pluginConfig !== null && pluginConfig !== void 0 ? pluginConfig : {};
|
|
29
|
+
const appUrl = new URL(APP_URL);
|
|
30
|
+
const { [utils_1.PAGE_ROUTE_NAMES.EXIT]: pageRouteExit, [utils_1.PAGE_ROUTE_NAMES.ERROR]: pageRouteError, [utils_1.API_ROUTE_NAMES.AUTH]: apiRouteAuth, [utils_1.API_ROUTE_NAMES.AUTH_CALLBACK]: apiRouteAuthCallback, [utils_1.API_ROUTE_NAMES.APP_UNINSTALLED]: apiRouteAppUninstalled, } = await next_plugins_1.getPrompts([
|
|
31
|
+
{
|
|
32
|
+
type: 'text',
|
|
33
|
+
name: utils_1.API_ROUTE_NAMES.AUTH_CALLBACK,
|
|
34
|
+
message: 'API Route: Auth Callback',
|
|
35
|
+
initial: [_apiRouteParamAuthCallback, _apiRouteAuthCallback].find(utils_1.stringNotEmpty),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: 'text',
|
|
39
|
+
name: utils_1.API_ROUTE_NAMES.AUTH,
|
|
40
|
+
message: 'API Route: Auth',
|
|
41
|
+
initial: [_apiRouteParamAuth, _apiRouteAuth].find(utils_1.stringNotEmpty),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'text',
|
|
45
|
+
name: utils_1.API_ROUTE_NAMES.APP_UNINSTALLED,
|
|
46
|
+
message: 'API Route: Uninstalled Webhook',
|
|
47
|
+
initial: [_apiRouteParamAppUninstalled, _apiRouteAppUninstalled].find(utils_1.stringNotEmpty),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'text',
|
|
51
|
+
name: utils_1.PAGE_ROUTE_NAMES.EXIT,
|
|
52
|
+
message: 'Page Route: Exit',
|
|
53
|
+
initial: [_pageRouteParamExit, _pageRouteExit].find(utils_1.stringNotEmpty),
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'text',
|
|
57
|
+
name: utils_1.PAGE_ROUTE_NAMES.ERROR,
|
|
58
|
+
message: 'Page Route: Error',
|
|
59
|
+
initial: [_pageRouteParamError, _pageRouteError].find(utils_1.stringNotEmpty),
|
|
60
|
+
}
|
|
61
|
+
], { phase: nextPhase, disabled: !utils_1.isTrue(interactive) });
|
|
62
|
+
const PAGE_ROUTES = {
|
|
63
|
+
[utils_1.PAGE_ROUTE_NAMES.EXIT]: pageRouteExit,
|
|
64
|
+
[utils_1.PAGE_ROUTE_NAMES.ERROR]: pageRouteError,
|
|
65
|
+
};
|
|
66
|
+
const PAGE_PATHS = Object.entries(PAGE_ROUTES).reduce((_pagePaths, [routeName, routePath]) => (Object.assign(Object.assign({}, _pagePaths), { [routeName]: `${basePath}${routePath}` })), {});
|
|
67
|
+
const API_ROUTES = {
|
|
68
|
+
[utils_1.API_ROUTE_NAMES.AUTH]: apiRouteAuth,
|
|
69
|
+
[utils_1.API_ROUTE_NAMES.AUTH_CALLBACK]: apiRouteAuthCallback,
|
|
70
|
+
[utils_1.API_ROUTE_NAMES.APP_UNINSTALLED]: apiRouteAppUninstalled,
|
|
71
|
+
};
|
|
72
|
+
const API_PATHS = Object.entries(API_ROUTES).reduce((_apiPaths, [routeName, routePath]) => (Object.assign(Object.assign({}, _apiPaths), { [routeName]: `${basePath}${routePath}` })), {});
|
|
73
|
+
const APP_CALLBACK_URI = `${APP_URL}${API_PATHS[utils_1.API_ROUTE_NAMES.AUTH_CALLBACK]}`;
|
|
74
|
+
const APP_HOST_NAME = appUrl.hostname;
|
|
75
|
+
const APP_CONFIG = {
|
|
76
|
+
API_VERSION: SHOPIFY_API_VERSION,
|
|
77
|
+
API_KEY: SHOPIFY_API_PUBLIC_KEY,
|
|
78
|
+
API_SECRET_KEY: SHOPIFY_API_KEY,
|
|
79
|
+
HOST_NAME: APP_HOST_NAME,
|
|
80
|
+
HOST_SCHEME: appUrl.protocol.replace(':', ''),
|
|
81
|
+
SCOPES: SHOPIFY_API_SCOPES.replace(/, /g, ',').split(','),
|
|
82
|
+
IS_EMBEDDED_APP: true,
|
|
83
|
+
};
|
|
84
|
+
const APP_WEBHOOKS = {
|
|
85
|
+
APP_UNINSTALLED: [{
|
|
86
|
+
path: API_PATHS[utils_1.API_ROUTE_NAMES.APP_UNINSTALLED],
|
|
87
|
+
}],
|
|
88
|
+
};
|
|
89
|
+
// TODO!!!: move to use firebase-admin
|
|
90
|
+
// TODO: update to use credential & databaseURL only AND update FB rule to:
|
|
91
|
+
// match /oauth-data/{document=**} {
|
|
92
|
+
// allow read, write: if request.auth.uid != null;
|
|
93
|
+
// }
|
|
94
|
+
// TODO: change to use shared helper?
|
|
95
|
+
const FB_CONFIG = {
|
|
96
|
+
// credential: admin.credential.cert(config),
|
|
97
|
+
appId: NEXT_PUBLIC_FB_APP_ID,
|
|
98
|
+
apiKey: FB_API_KEY,
|
|
99
|
+
projectId: FB_PROJECT_ID,
|
|
100
|
+
databaseURL: `https://${FB_PROJECT_ID}.firebaseio.com`,
|
|
101
|
+
};
|
|
102
|
+
const isExportMode = nextPhase === constants_1.PHASE_EXPORT;
|
|
103
|
+
const isDevMode = nextPhase === constants_1.PHASE_DEVELOPMENT_SERVER;
|
|
104
|
+
const headers = async () => {
|
|
105
|
+
const baseHeaders = _headers ? await _headers() : [];
|
|
106
|
+
if (!isDevMode) {
|
|
107
|
+
return baseHeaders;
|
|
108
|
+
}
|
|
109
|
+
return [
|
|
110
|
+
...baseHeaders,
|
|
111
|
+
...Object.keys(API_ROUTES).map((source) => ({
|
|
112
|
+
source,
|
|
113
|
+
headers: [
|
|
114
|
+
{
|
|
115
|
+
key: 'Access-Control-Allow-Methods',
|
|
116
|
+
value: 'GET',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
key: 'Access-Control-Allow-Credentials',
|
|
120
|
+
value: 'false',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
key: 'Access-Control-Allow-Origin',
|
|
124
|
+
value: '*',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
key: 'Access-Control-Allow-Headers',
|
|
128
|
+
value: '*',
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
}))
|
|
132
|
+
];
|
|
133
|
+
};
|
|
134
|
+
const serverRuntimeConfig = Object.assign(Object.assign({}, _serverRuntimeConfig), { FB_CONFIG,
|
|
135
|
+
FB_ROOT_COLLECTION,
|
|
136
|
+
APP_CONFIG,
|
|
137
|
+
APP_WEBHOOKS,
|
|
138
|
+
PAGE_ROUTES,
|
|
139
|
+
PAGE_PATHS,
|
|
140
|
+
API_ROUTES,
|
|
141
|
+
API_PATHS,
|
|
142
|
+
APP_ID,
|
|
143
|
+
APP_CALLBACK_URI,
|
|
144
|
+
APP_STATE_COOKIE_NAME });
|
|
145
|
+
return Object.assign(Object.assign(Object.assign({}, _nextConfig), { basePath: _basePath, serverRuntimeConfig }), !isExportMode && {
|
|
146
|
+
headers,
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
exports.withShopify = withShopify;
|
|
150
|
+
//# sourceMappingURL=withShopify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withShopify.js","sourceRoot":"","sources":["../src/withShopify.js"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,4BAA4B;AAC5B,8CAGuB;AAEvB,0DAAoD;AAEpD,mCAMgB;AAEhB,mDAAmD;AAE5C,MAAM,WAAW,GAAG,KAAK,EAAE,SAAS,EAAE,EAAyB,EAAE,EAAE;QAA7B,EAAE,UAAU,OAAa,EAAR,MAAM,cAAvB,cAAyB,CAAF;IAClE,MAAM,KAKF,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,EALd,EACJ,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,QAAQ,EACjB,mBAAmB,EAAE,oBAAoB,GAAG,EAAE,OAE5B,EADf,WAAW,cAJV,8CAKL,CAAmB,CAAA;IAEpB,MAAM,KAIF,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,EAJV;IACJ,6DAA6D;IAC7D,aAAa,OAEC,EAFC,sDAAsD;IAClE,YAAY,cAHX,iBAIL,CAAe,CAAA;IAEhB,MAAM,QAAQ,GAAG,oBAAY,CAAC,SAAS,CAAC,CAAA;IAExC,MAAM,EACJ,WAAW,EACX,UAAU,EAAE,EACV,CAAC,wBAAgB,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,EACjD,CAAC,wBAAgB,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,QAAQ,GACrD,EACD,SAAS,EAAE,EACT,CAAC,uBAAe,CAAC,IAAI,CAAC,EAAE,aAAa,GAAG,WAAW,EACnD,CAAC,uBAAe,CAAC,aA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AAA;IAC/C,MAAM,SAAS,GAAG,SAAS,KAAK,oCAAwB,CAAA;IAExD,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE;QACzB,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QAEpD,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,WAAW,CAAA;SACnB;QAED,OAAO;YACL,GAAG,WAAW;YACd,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBAC1C,MAAM;gBACN,OAAO,EAAE;oBACP;wBACE,GAAG,EAAE,8BAA8B;wBACnC,KAAK,EAAE,KAAK;qBACb;oBACD;wBACE,GAAG,EAAE,kCAAkC;wBACvC,KAAK,EAAE,OAAO;qBACf;oBACD;wBACE,GAAG,EAAE,6BAA6B;wBAClC,KAAK,EAAE,GAAG;qBACX;oBACD;wBACE,GAAG,EAAE,8BAA8B;wBACnC,KAAK,EAAE,GAAG;qBACX;iBACF;aACF,CAAC,CAAC;SACJ,CAAA;IACH,CAAC,CAAA;IAED,MAAM,mBAAmB,mCACpB,oBAAoB,KACvB,SAAS;QACT,kBAAkB;QAClB,UAAU;QACV,YAAY;QACZ,WAAW;QACX,UAAU;QACV,UAAU;QACV,SAAS;QACT,MAAM;QACN,gBAAgB;QAChB,qBAAqB,GACtB,CAAA;IAED,qDACK,WAAW,KACd,QAAQ,EAAE,SAAS,EACnB,mBAAmB,KAChB,CAAC,YAAY,IAAI;QAClB,OAAO;KACR,EAIF;AACH,CAAC,CAAA;AA5MY,QAAA,WAAW,eA4MvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnostack/next-shopify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-alpha.1",
|
|
4
4
|
"author": "agnoStack Dev <developers@agnostack.com> (https://agnostack.com)",
|
|
5
5
|
"owner": "agnoStack",
|
|
6
6
|
"description": "Please contact agnoStack via info@agnostack.com for any questions",
|
|
@@ -40,17 +40,17 @@
|
|
|
40
40
|
]
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"next": "^12.1.0",
|
|
43
|
+
"next": "^12.1.0 || ^13.0.0",
|
|
44
44
|
"react": "^17.0.2 || ^18.0.0-0",
|
|
45
45
|
"react-dom": "^17.0.2 || ^18.0.0-0",
|
|
46
|
-
"react-is": "^17.0.2 || ^18.0.0-0"
|
|
47
|
-
"prompts": "^2.4.0"
|
|
46
|
+
"react-is": "^17.0.2 || ^18.0.0-0"
|
|
48
47
|
},
|
|
49
48
|
"dependencies": {
|
|
49
|
+
"@agnostack/next-plugins": "latest",
|
|
50
|
+
"@shopify/shopify-api": "5.2.0",
|
|
50
51
|
"browser-monads": "1.0.0",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"mustache": "4.2.0",
|
|
52
|
+
"cookies": "0.8.0",
|
|
53
|
+
"firebase": "9.13.0",
|
|
54
54
|
"nextjs-cors": "2.1.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
package/dist/utils/data.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export const ASSET_URL_PREFIX: "assets/";
|
|
2
|
-
export function getEnv(): {
|
|
3
|
-
params: object;
|
|
4
|
-
args: any[];
|
|
5
|
-
env: object;
|
|
6
|
-
nextEnv: {};
|
|
7
|
-
definePluginEnv: {};
|
|
8
|
-
};
|
|
9
|
-
export function arrowsReplace(template: any, replacements: any): any;
|
|
10
|
-
export function generateReplacements(_replacements: any): any;
|
|
11
|
-
export function getAppData(manifestTemplate: any, replacements: any, mergeData: any): {
|
|
12
|
-
safData: {
|
|
13
|
-
context: {
|
|
14
|
-
host: string;
|
|
15
|
-
product: any;
|
|
16
|
-
location: any;
|
|
17
|
-
instanceGuid: any;
|
|
18
|
-
account: {
|
|
19
|
-
subdomain: any;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
metadata: {
|
|
23
|
-
plan: {
|
|
24
|
-
name: any;
|
|
25
|
-
};
|
|
26
|
-
stripe_subscription_id: any;
|
|
27
|
-
appId: any;
|
|
28
|
-
name: any;
|
|
29
|
-
installationId: any;
|
|
30
|
-
version: any;
|
|
31
|
-
settings: any;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
manifestData: any;
|
|
35
|
-
installationData: any;
|
|
36
|
-
};
|
|
37
|
-
export function getZendeskData({ pluginConfig, ...replacements }: {
|
|
38
|
-
[x: string]: any;
|
|
39
|
-
pluginConfig: any;
|
|
40
|
-
}): {
|
|
41
|
-
zendeskData: any;
|
|
42
|
-
safData: {
|
|
43
|
-
context: {
|
|
44
|
-
host: string;
|
|
45
|
-
product: any;
|
|
46
|
-
location: any;
|
|
47
|
-
instanceGuid: any;
|
|
48
|
-
account: {
|
|
49
|
-
subdomain: any;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
metadata: {
|
|
53
|
-
plan: {
|
|
54
|
-
name: any;
|
|
55
|
-
};
|
|
56
|
-
stripe_subscription_id: any;
|
|
57
|
-
appId: any;
|
|
58
|
-
name: any;
|
|
59
|
-
installationId: any;
|
|
60
|
-
version: any;
|
|
61
|
-
settings: any;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
manifestData: any;
|
|
65
|
-
installationData: any;
|
|
66
|
-
};
|
|
67
|
-
export function getPrompts(_questions: any, { phase, disabled }?: {
|
|
68
|
-
phase: any;
|
|
69
|
-
disabled: any;
|
|
70
|
-
}): Promise<any>;
|
package/dist/utils/data.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getPrompts = exports.getZendeskData = exports.getAppData = exports.generateReplacements = exports.arrowsReplace = exports.getEnv = exports.ASSET_URL_PREFIX = void 0;
|
|
18
|
-
const fs_1 = __importDefault(require("fs"));
|
|
19
|
-
const path_1 = __importDefault(require("path"));
|
|
20
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
21
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
22
|
-
const browser_monads_1 = require("browser-monads");
|
|
23
|
-
const constants_1 = require("next/constants");
|
|
24
|
-
const display_1 = require("./display");
|
|
25
|
-
const locations_1 = require("./locations");
|
|
26
|
-
exports.ASSET_URL_PREFIX = 'assets/';
|
|
27
|
-
const cleanEnv = (env) => (Object.entries(display_1.ensureObject(env)).reduce((_env, [key, val]) => (Object.assign(Object.assign({}, _env), !(key.startsWith('__') || key.startsWith('NODE_')) && {
|
|
28
|
-
[key]: val,
|
|
29
|
-
})), {}));
|
|
30
|
-
const stringifyEnv = (env) => (Object.entries(display_1.ensureObject(env)).reduce((_env, [key, val]) => (Object.assign(Object.assign({}, _env), {
|
|
31
|
-
// NOTE: DefinePlugin requires stringified
|
|
32
|
-
[key]: JSON.stringify(val) })), {}));
|
|
33
|
-
// TODO!!!!: move getEnvData to lib-core (or somewhere)?
|
|
34
|
-
const getEnv = () => {
|
|
35
|
-
const { ENVIRONMENT, NODE_ENV } = process.env;
|
|
36
|
-
const _environment = [ENVIRONMENT, NODE_ENV, 'development'].find((value) => display_1.stringNotEmpty(value));
|
|
37
|
-
// eslint-disable-next-line import/order, global-require, @typescript-eslint/no-var-requires
|
|
38
|
-
const { parsed: envFlow } = require('dotenv-flow').config({
|
|
39
|
-
node_env: _environment,
|
|
40
|
-
});
|
|
41
|
-
const mergedEnv = display_1.deepmerge.all([
|
|
42
|
-
process.env,
|
|
43
|
-
envFlow,
|
|
44
|
-
{ ENVIRONMENT: _environment }
|
|
45
|
-
]);
|
|
46
|
-
const { params, args } = process.argv.reduce(({ args: _args, params: _params, }, data) => {
|
|
47
|
-
const [_param, value] = data.split('=');
|
|
48
|
-
const param = _param.replace('--', '');
|
|
49
|
-
return {
|
|
50
|
-
args: [
|
|
51
|
-
..._args,
|
|
52
|
-
...!value ? [param] : []
|
|
53
|
-
],
|
|
54
|
-
params: Object.assign(Object.assign({}, _params), value && {
|
|
55
|
-
[param]: value,
|
|
56
|
-
}),
|
|
57
|
-
};
|
|
58
|
-
}, {
|
|
59
|
-
args: [],
|
|
60
|
-
params: mergedEnv,
|
|
61
|
-
});
|
|
62
|
-
return {
|
|
63
|
-
params,
|
|
64
|
-
args,
|
|
65
|
-
env: mergedEnv,
|
|
66
|
-
nextEnv: cleanEnv(mergedEnv),
|
|
67
|
-
definePluginEnv: stringifyEnv(mergedEnv),
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
exports.getEnv = getEnv;
|
|
71
|
-
const getProductIcon = ({ product, location, isMultiProduct }) => {
|
|
72
|
-
var _a;
|
|
73
|
-
let productIcon;
|
|
74
|
-
// NOTE: if running in browser/old node version/old webpack version may not have method
|
|
75
|
-
if (fs_1.default === null || fs_1.default === void 0 ? void 0 : fs_1.default.existsSync) {
|
|
76
|
-
if (!((_a = locations_1.ICON_LOCATION_ALLOWLIST[product]) === null || _a === void 0 ? void 0 : _a.includes(location))) {
|
|
77
|
-
return productIcon;
|
|
78
|
-
}
|
|
79
|
-
const svgPath = isMultiProduct ? `${product}/icon_${location}.svg` : `icon_${location}.svg`;
|
|
80
|
-
const baseIconPath = path_1.default.resolve(__dirname);
|
|
81
|
-
const imagePaths = [svgPath, path_1.default.join('assets', svgPath), path_1.default.join('images', svgPath)];
|
|
82
|
-
// NOTE: intentionally using for loops instead of map so we can break to exit quickly soon as matched
|
|
83
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
84
|
-
for (const imagePath of imagePaths) {
|
|
85
|
-
if (fs_1.default.existsSync(path_1.default.join(baseIconPath, 'public', imagePath))) {
|
|
86
|
-
productIcon = {
|
|
87
|
-
svg: imagePath,
|
|
88
|
-
// HMMM: active/inactive/hover??
|
|
89
|
-
};
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return productIcon;
|
|
95
|
-
};
|
|
96
|
-
const getIconsByProduct = ({ product, productLocations, isMultiProduct }) => (Object.entries(productLocations).reduce((productLocationIcons, [location]) => {
|
|
97
|
-
const productIcon = getProductIcon({ product, location, isMultiProduct });
|
|
98
|
-
return Object.assign(Object.assign({}, productLocationIcons), (productIcon && {
|
|
99
|
-
[location]: productIcon,
|
|
100
|
-
}));
|
|
101
|
-
}, {}));
|
|
102
|
-
// HMMMMM: optimize this method!
|
|
103
|
-
const normalizeLocations = (_locations) => {
|
|
104
|
-
var _a, _b;
|
|
105
|
-
const locations = display_1.ensureObject(_locations);
|
|
106
|
-
const isMultiProduct = Object.keys(locations) > 1;
|
|
107
|
-
const productIcons = Object.entries(locations).reduce((_productIcons, [product, productLocations]) => (Object.assign(Object.assign({}, _productIcons), { [product]: getIconsByProduct({ product, productLocations, isMultiProduct }) })), {});
|
|
108
|
-
for (const product in productIcons) {
|
|
109
|
-
for (const locationName in productIcons[product]) {
|
|
110
|
-
if (typeof locations[product][locationName] === 'string') {
|
|
111
|
-
locations[product][locationName] = {
|
|
112
|
-
url: display_1.cleanURL(locations[product][locationName]),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
if (typeof ((_a = locations[product][locationName]) === null || _a === void 0 ? void 0 : _a.url) === 'string') {
|
|
116
|
-
locations[product][locationName] = Object.assign(Object.assign({}, locations[product][locationName]), { url: display_1.cleanURL(locations[product][locationName].url) });
|
|
117
|
-
}
|
|
118
|
-
if (productIcons[product][locationName].svg) {
|
|
119
|
-
locations[product][locationName].svg = productIcons[product][locationName].svg;
|
|
120
|
-
}
|
|
121
|
-
if (productIcons[product][locationName].active) {
|
|
122
|
-
locations[product][locationName].active = productIcons[product][locationName].active;
|
|
123
|
-
}
|
|
124
|
-
if (productIcons[product][locationName].inactive) {
|
|
125
|
-
locations[product][locationName].inactive = productIcons[product][locationName].inactive;
|
|
126
|
-
}
|
|
127
|
-
if (productIcons[product][locationName].hover) {
|
|
128
|
-
locations[product][locationName].hover = productIcons[product][locationName].hover;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// Handle the case where an app installation location is not an object but is a string,
|
|
133
|
-
for (const product in locations) {
|
|
134
|
-
for (const locationName in locations[product]) {
|
|
135
|
-
if (typeof locations[product][locationName] === 'string') {
|
|
136
|
-
locations[product][locationName] = {
|
|
137
|
-
url: display_1.cleanURL(locations[product][locationName]),
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
else if (typeof ((_b = locations[product][locationName]) === null || _b === void 0 ? void 0 : _b.url) === 'string') {
|
|
141
|
-
locations[product][locationName] = Object.assign(Object.assign({}, locations[product][locationName]), { url: display_1.cleanURL(locations[product][locationName].url) });
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return locations;
|
|
146
|
-
};
|
|
147
|
-
const templateReplace = (template, replacements, partials, tokens) => {
|
|
148
|
-
// NOTE: fixes issues where by default standard characters are HTML encoded (https://stackoverflow.com/questions/22910428/mustache-globally-disable-html-escaping)
|
|
149
|
-
mustache_1.default.escape = (value) => (value);
|
|
150
|
-
return mustache_1.default.render(display_1.ensureString(template), display_1.ensureObject(replacements), partials, tokens);
|
|
151
|
-
};
|
|
152
|
-
const arrowsReplace = (template, replacements) => (templateReplace(template, display_1.cleanObject(replacements), {}, ['<<', '>>']));
|
|
153
|
-
exports.arrowsReplace = arrowsReplace;
|
|
154
|
-
const arrowsItemReplace = (value, replacements) => (display_1.isType(value, 'object')
|
|
155
|
-
? Object.entries(value).reduce((_data, [_key, _value]) => (Object.assign(Object.assign({}, _data), { [_key]: exports.arrowsReplace(_value, replacements) })), {})
|
|
156
|
-
: exports.arrowsReplace(value, replacements));
|
|
157
|
-
const generateReplacements = (_replacements) => {
|
|
158
|
-
const replacements = display_1.cleanObject(_replacements);
|
|
159
|
-
return display_1.cleanObject(Object.entries(replacements).reduce((data, [key, _value]) => {
|
|
160
|
-
// eslint-disable-next-line no-nested-ternary
|
|
161
|
-
const value = Array.isArray(_value)
|
|
162
|
-
? _value.reduce((_data, __value) => ([
|
|
163
|
-
..._data,
|
|
164
|
-
arrowsItemReplace(__value, replacements)
|
|
165
|
-
]), [])
|
|
166
|
-
: arrowsItemReplace(_value, replacements);
|
|
167
|
-
return Object.assign(Object.assign({}, data), { [key]: value });
|
|
168
|
-
}, {}));
|
|
169
|
-
};
|
|
170
|
-
exports.generateReplacements = generateReplacements;
|
|
171
|
-
const getRouteReplacements = (_locations, defaultRoute = '/index.html') => {
|
|
172
|
-
const locations = display_1.ensureObject(_locations);
|
|
173
|
-
return {
|
|
174
|
-
location: normalizeLocations(locations),
|
|
175
|
-
// NOTE: this generates a default set of routes that can be override by any passed in..BUT not sure how location.product factors in here
|
|
176
|
-
routes: Object.values(locations).reduce((_routes, productLocations) => (Object.assign(Object.assign({}, _routes), Object.keys(display_1.ensureObject(productLocations)).reduce((_locationRoutes, productLocation) => (Object.assign(Object.assign({}, _locationRoutes), { [productLocation]: defaultRoute })), {}))), {}),
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
const getManifestData = (manifestTemplate, _replacements, mergeData) => {
|
|
180
|
-
var _a;
|
|
181
|
-
const data = display_1.cleanObject(display_1.deepmerge(display_1.ensureObject(manifestTemplate), exports.generateReplacements(mergeData)));
|
|
182
|
-
const replacements = exports.generateReplacements(_replacements);
|
|
183
|
-
return JSON.parse(exports.arrowsReplace(JSON.stringify(data, null, 2), display_1.deepmerge(getRouteReplacements(data === null || data === void 0 ? void 0 : data.location, (_a = replacements === null || replacements === void 0 ? void 0 : replacements.routes) === null || _a === void 0 ? void 0 : _a.default), replacements)));
|
|
184
|
-
};
|
|
185
|
-
const getAppData = (manifestTemplate, replacements, mergeData) => {
|
|
186
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
|
|
187
|
-
const manifestData = getManifestData(manifestTemplate, replacements, mergeData);
|
|
188
|
-
const _10 = exports.generateReplacements(mergeData), { settings } = _10, _installationData = __rest(_10, ["settings"]);
|
|
189
|
-
const defaultSettings = display_1.ensureArray(manifestData === null || manifestData === void 0 ? void 0 : manifestData.parameters).reduce((_parameters, { name: _name, default: defaultValue }) => {
|
|
190
|
-
var _a;
|
|
191
|
-
return (Object.assign(Object.assign({}, _parameters), { [_name]: (_a = _parameters[_name]) !== null && _a !== void 0 ? _a : defaultValue }));
|
|
192
|
-
}, display_1.ensureObject(replacements === null || replacements === void 0 ? void 0 : replacements.parameters));
|
|
193
|
-
const installationData = Object.assign(Object.assign({ id: (_c = (_b = (_a = replacements === null || replacements === void 0 ? void 0 : replacements.installation_id) !== null && _a !== void 0 ? _a : replacements === null || replacements === void 0 ? void 0 : replacements.installationId) !== null && _b !== void 0 ? _b : replacements === null || replacements === void 0 ? void 0 : replacements.id) !== null && _c !== void 0 ? _c : display_1.getInteger(), app_id: (_e = (_d = replacements === null || replacements === void 0 ? void 0 : replacements.app_id) !== null && _d !== void 0 ? _d : replacements === null || replacements === void 0 ? void 0 : replacements.appId) !== null && _e !== void 0 ? _e : display_1.getInteger(), instance_guid: (_h = (_g = (_f = replacements === null || replacements === void 0 ? void 0 : replacements.instance_guid) !== null && _f !== void 0 ? _f : replacements === null || replacements === void 0 ? void 0 : replacements.instanceGUID) !== null && _g !== void 0 ? _g : replacements === null || replacements === void 0 ? void 0 : replacements.instanceGuid) !== null && _h !== void 0 ? _h : display_1.getGUID(), host_name: (_l = (_k = (_j = replacements === null || replacements === void 0 ? void 0 : replacements.host_name) !== null && _j !== void 0 ? _j : replacements === null || replacements === void 0 ? void 0 : replacements.host) !== null && _k !== void 0 ? _k : replacements === null || replacements === void 0 ? void 0 : replacements.hostName) !== null && _l !== void 0 ? _l : browser_monads_1.window.location.host, product: (_m = replacements === null || replacements === void 0 ? void 0 : replacements.product) !== null && _m !== void 0 ? _m : locations_1.PRODUCTS.SUPPORT, location: (_o = replacements === null || replacements === void 0 ? void 0 : replacements.location) !== null && _o !== void 0 ? _o : locations_1.LOCATIONS.SIDEBAR_TICKET, app_owner: (_p = replacements === null || replacements === void 0 ? void 0 : replacements.app_owner) !== null && _p !== void 0 ? _p : replacements === null || replacements === void 0 ? void 0 : replacements.owner, app_name: (_t = (_s = (_r = (_q = replacements === null || replacements === void 0 ? void 0 : replacements.app_name) !== null && _q !== void 0 ? _q : replacements === null || replacements === void 0 ? void 0 : replacements.appName) !== null && _r !== void 0 ? _r : manifestData === null || manifestData === void 0 ? void 0 : manifestData.appName) !== null && _s !== void 0 ? _s : replacements === null || replacements === void 0 ? void 0 : replacements.name) !== null && _t !== void 0 ? _t : manifestData === null || manifestData === void 0 ? void 0 : manifestData.name, app_name_short: (_x = (_w = (_v = (_u = replacements === null || replacements === void 0 ? void 0 : replacements.app_name_short) !== null && _u !== void 0 ? _u : replacements === null || replacements === void 0 ? void 0 : replacements.shortName) !== null && _v !== void 0 ? _v : manifestData === null || manifestData === void 0 ? void 0 : manifestData.shortName) !== null && _w !== void 0 ? _w : replacements === null || replacements === void 0 ? void 0 : replacements.name) !== null && _x !== void 0 ? _x : manifestData === null || manifestData === void 0 ? void 0 : manifestData.name, app_version: (_z = (_y = replacements === null || replacements === void 0 ? void 0 : replacements.app_version) !== null && _y !== void 0 ? _y : replacements === null || replacements === void 0 ? void 0 : replacements.version) !== null && _z !== void 0 ? _z : manifestData === null || manifestData === void 0 ? void 0 : manifestData.version, terms_conditions_url: (_1 = (_0 = replacements === null || replacements === void 0 ? void 0 : replacements.terms_conditions_url) !== null && _0 !== void 0 ? _0 : replacements === null || replacements === void 0 ? void 0 : replacements.termsConditionsURL) !== null && _1 !== void 0 ? _1 : manifestData === null || manifestData === void 0 ? void 0 : manifestData.termsConditionsURL, app_locations: normalizeLocations((_3 = (_2 = replacements === null || replacements === void 0 ? void 0 : replacements.app_locations) !== null && _2 !== void 0 ? _2 : replacements === null || replacements === void 0 ? void 0 : replacements.locations) !== null && _3 !== void 0 ? _3 : manifestData === null || manifestData === void 0 ? void 0 : manifestData.location) }, _installationData), { settings: display_1.deepmerge(exports.generateReplacements(defaultSettings), display_1.ensureObject(settings)) });
|
|
194
|
-
const subscriptionId = (_5 = (_4 = replacements === null || replacements === void 0 ? void 0 : replacements.stripe_subscription_id) !== null && _4 !== void 0 ? _4 : replacements === null || replacements === void 0 ? void 0 : replacements.subscription_id) !== null && _5 !== void 0 ? _5 : replacements === null || replacements === void 0 ? void 0 : replacements.subscriptionId;
|
|
195
|
-
const subscriptionData = Object.assign(Object.assign({}, subscriptionId && {
|
|
196
|
-
stripe_subscription_id: subscriptionId,
|
|
197
|
-
}), { plan: {
|
|
198
|
-
name: (_9 = (_8 = (_7 = (_6 = replacements === null || replacements === void 0 ? void 0 : replacements.stripe_subscription_plan) !== null && _6 !== void 0 ? _6 : replacements === null || replacements === void 0 ? void 0 : replacements.subscription_plan) !== null && _7 !== void 0 ? _7 : replacements === null || replacements === void 0 ? void 0 : replacements.subscriptionPlan) !== null && _8 !== void 0 ? _8 : replacements === null || replacements === void 0 ? void 0 : replacements.plan) !== null && _9 !== void 0 ? _9 : null,
|
|
199
|
-
} });
|
|
200
|
-
const safData = {
|
|
201
|
-
context: {
|
|
202
|
-
host: 'zendesk',
|
|
203
|
-
product: installationData.product,
|
|
204
|
-
location: installationData.location,
|
|
205
|
-
instanceGuid: installationData.instance_guid,
|
|
206
|
-
account: {
|
|
207
|
-
subdomain: installationData.host_name,
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
metadata: Object.assign({ appId: installationData.app_id, name: installationData.app_name, installationId: installationData.id, version: installationData.app_version, settings: installationData.settings }, subscriptionData),
|
|
211
|
-
};
|
|
212
|
-
return {
|
|
213
|
-
safData,
|
|
214
|
-
manifestData,
|
|
215
|
-
installationData,
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
exports.getAppData = getAppData;
|
|
219
|
-
const getZendeskData = (_a) => {
|
|
220
|
-
var { pluginConfig } = _a, replacements = __rest(_a, ["pluginConfig"]);
|
|
221
|
-
const _b = pluginConfig !== null && pluginConfig !== void 0 ? pluginConfig : {}, { routes = {}, data = {}, manifestTemplate } = _b, zendeskData = __rest(_b, ["routes", "data", "manifestTemplate"]);
|
|
222
|
-
return Object.assign(Object.assign({}, exports.getAppData(manifestTemplate, Object.assign(Object.assign(Object.assign({}, display_1.cleanObject(replacements)), display_1.cleanObject(data)), display_1.objectNotEmpty(display_1.cleanObject(routes)) && {
|
|
223
|
-
routes,
|
|
224
|
-
}))), display_1.objectNotEmpty(display_1.cleanObject(zendeskData)) && {
|
|
225
|
-
zendeskData,
|
|
226
|
-
});
|
|
227
|
-
};
|
|
228
|
-
exports.getZendeskData = getZendeskData;
|
|
229
|
-
// TODO: externalize to shared project (shared w/ next-zcli & next-shopify)
|
|
230
|
-
const getPrompts = async (_questions, { phase, disabled } = {}) => {
|
|
231
|
-
const questions = display_1.ensureArray(_questions).reduce((__questions, _a) => {
|
|
232
|
-
var { name, message } = _a, question = __rest(_a, ["name", "message"]);
|
|
233
|
-
return ([
|
|
234
|
-
...__questions,
|
|
235
|
-
Object.assign(Object.assign({ name }, question), message && {
|
|
236
|
-
message: `[${name}] ${message}`,
|
|
237
|
-
})
|
|
238
|
-
]);
|
|
239
|
-
}, []);
|
|
240
|
-
let values = questions.reduce((_values, { name, initial: value }) => (Object.assign(Object.assign({}, _values), { [name]: value })), {});
|
|
241
|
-
if (phase === constants_1.PHASE_DEVELOPMENT_SERVER) {
|
|
242
|
-
if (!disabled) {
|
|
243
|
-
try {
|
|
244
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
245
|
-
const prompts = require('prompts');
|
|
246
|
-
values = await prompts(questions);
|
|
247
|
-
}
|
|
248
|
-
catch (_ignore) {
|
|
249
|
-
console.warn(`${chalk_1.default.yellow('warn')} - ${
|
|
250
|
-
// eslint-disable-next-line max-len
|
|
251
|
-
chalk_1.default.yellow(`Ignoring ${chalk_1.default.bold("missing 'devDependency' for 'prompts'")} - required when setting 'interactive: true'`)}`);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
Object.entries(values).forEach(([name, value]) => {
|
|
256
|
-
var _a;
|
|
257
|
-
const { message } = (_a = questions.find((question) => question.name === name)) !== null && _a !== void 0 ? _a : {};
|
|
258
|
-
if (message) {
|
|
259
|
-
console.info(`${chalk_1.default.yellowBright('next-zcli')} - ${chalk_1.default.bold(message)}: ${value}`);
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
console.info(`${chalk_1.default.yellowBright('next-zcli')} - [${chalk_1.default.bold(name)}]: ${value}`);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return values;
|
|
268
|
-
};
|
|
269
|
-
exports.getPrompts = getPrompts;
|
|
270
|
-
//# sourceMappingURL=data.js.map
|