@curless/shopify-storefront 0.1.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.
Files changed (129) hide show
  1. package/dist/__tests__/card-contract.test.d.ts +2 -0
  2. package/dist/__tests__/card-contract.test.d.ts.map +1 -0
  3. package/dist/__tests__/card-contract.test.js +22 -0
  4. package/dist/__tests__/card-contract.test.js.map +1 -0
  5. package/dist/__tests__/catalog-registry.test.d.ts +2 -0
  6. package/dist/__tests__/catalog-registry.test.d.ts.map +1 -0
  7. package/dist/__tests__/catalog-registry.test.js +109 -0
  8. package/dist/__tests__/catalog-registry.test.js.map +1 -0
  9. package/dist/__tests__/challenge.test.d.ts +2 -0
  10. package/dist/__tests__/challenge.test.d.ts.map +1 -0
  11. package/dist/__tests__/challenge.test.js +46 -0
  12. package/dist/__tests__/challenge.test.js.map +1 -0
  13. package/dist/__tests__/config.test.d.ts +2 -0
  14. package/dist/__tests__/config.test.d.ts.map +1 -0
  15. package/dist/__tests__/config.test.js +123 -0
  16. package/dist/__tests__/config.test.js.map +1 -0
  17. package/dist/__tests__/connection-state.test.d.ts +2 -0
  18. package/dist/__tests__/connection-state.test.d.ts.map +1 -0
  19. package/dist/__tests__/connection-state.test.js +40 -0
  20. package/dist/__tests__/connection-state.test.js.map +1 -0
  21. package/dist/__tests__/multi-token-store.test.d.ts +2 -0
  22. package/dist/__tests__/multi-token-store.test.d.ts.map +1 -0
  23. package/dist/__tests__/multi-token-store.test.js +89 -0
  24. package/dist/__tests__/multi-token-store.test.js.map +1 -0
  25. package/dist/__tests__/oauth.test.d.ts +2 -0
  26. package/dist/__tests__/oauth.test.d.ts.map +1 -0
  27. package/dist/__tests__/oauth.test.js +112 -0
  28. package/dist/__tests__/oauth.test.js.map +1 -0
  29. package/dist/__tests__/output-schema.test.d.ts +2 -0
  30. package/dist/__tests__/output-schema.test.d.ts.map +1 -0
  31. package/dist/__tests__/output-schema.test.js +112 -0
  32. package/dist/__tests__/output-schema.test.js.map +1 -0
  33. package/dist/__tests__/ping.test.d.ts +2 -0
  34. package/dist/__tests__/ping.test.d.ts.map +1 -0
  35. package/dist/__tests__/ping.test.js +22 -0
  36. package/dist/__tests__/ping.test.js.map +1 -0
  37. package/dist/__tests__/rate-limit.test.d.ts +2 -0
  38. package/dist/__tests__/rate-limit.test.d.ts.map +1 -0
  39. package/dist/__tests__/rate-limit.test.js +46 -0
  40. package/dist/__tests__/rate-limit.test.js.map +1 -0
  41. package/dist/__tests__/stock.test.d.ts +2 -0
  42. package/dist/__tests__/stock.test.d.ts.map +1 -0
  43. package/dist/__tests__/stock.test.js +109 -0
  44. package/dist/__tests__/stock.test.js.map +1 -0
  45. package/dist/__tests__/tenant.test.d.ts +2 -0
  46. package/dist/__tests__/tenant.test.d.ts.map +1 -0
  47. package/dist/__tests__/tenant.test.js +105 -0
  48. package/dist/__tests__/tenant.test.js.map +1 -0
  49. package/dist/__tests__/tools.test.d.ts +2 -0
  50. package/dist/__tests__/tools.test.d.ts.map +1 -0
  51. package/dist/__tests__/tools.test.js +543 -0
  52. package/dist/__tests__/tools.test.js.map +1 -0
  53. package/dist/__tests__/upstream-cap.test.d.ts +2 -0
  54. package/dist/__tests__/upstream-cap.test.d.ts.map +1 -0
  55. package/dist/__tests__/upstream-cap.test.js +78 -0
  56. package/dist/__tests__/upstream-cap.test.js.map +1 -0
  57. package/dist/__tests__/webhooks.test.d.ts +2 -0
  58. package/dist/__tests__/webhooks.test.d.ts.map +1 -0
  59. package/dist/__tests__/webhooks.test.js +88 -0
  60. package/dist/__tests__/webhooks.test.js.map +1 -0
  61. package/dist/card.generated.d.ts +2 -0
  62. package/dist/card.generated.d.ts.map +1 -0
  63. package/dist/card.generated.js +6 -0
  64. package/dist/card.generated.js.map +1 -0
  65. package/dist/catalog-registry.d.ts +44 -0
  66. package/dist/catalog-registry.d.ts.map +1 -0
  67. package/dist/catalog-registry.js +105 -0
  68. package/dist/catalog-registry.js.map +1 -0
  69. package/dist/catalog.d.ts +51 -0
  70. package/dist/catalog.d.ts.map +1 -0
  71. package/dist/catalog.js +189 -0
  72. package/dist/catalog.js.map +1 -0
  73. package/dist/challenge.d.ts +11 -0
  74. package/dist/challenge.d.ts.map +1 -0
  75. package/dist/challenge.js +36 -0
  76. package/dist/challenge.js.map +1 -0
  77. package/dist/config.d.ts +141 -0
  78. package/dist/config.d.ts.map +1 -0
  79. package/dist/config.js +65 -0
  80. package/dist/config.js.map +1 -0
  81. package/dist/connection.d.ts +10 -0
  82. package/dist/connection.d.ts.map +1 -0
  83. package/dist/connection.js +21 -0
  84. package/dist/connection.js.map +1 -0
  85. package/dist/index.d.ts +3 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +974 -0
  88. package/dist/index.js.map +1 -0
  89. package/dist/legal.d.ts +52 -0
  90. package/dist/legal.d.ts.map +1 -0
  91. package/dist/legal.js +139 -0
  92. package/dist/legal.js.map +1 -0
  93. package/dist/load-config.d.ts +11 -0
  94. package/dist/load-config.d.ts.map +1 -0
  95. package/dist/load-config.js +23 -0
  96. package/dist/load-config.js.map +1 -0
  97. package/dist/multi-token-store.d.ts +18 -0
  98. package/dist/multi-token-store.d.ts.map +1 -0
  99. package/dist/multi-token-store.js +95 -0
  100. package/dist/multi-token-store.js.map +1 -0
  101. package/dist/oauth.d.ts +20 -0
  102. package/dist/oauth.d.ts.map +1 -0
  103. package/dist/oauth.js +123 -0
  104. package/dist/oauth.js.map +1 -0
  105. package/dist/rate-limit.d.ts +15 -0
  106. package/dist/rate-limit.d.ts.map +1 -0
  107. package/dist/rate-limit.js +56 -0
  108. package/dist/rate-limit.js.map +1 -0
  109. package/dist/stock.d.ts +39 -0
  110. package/dist/stock.d.ts.map +1 -0
  111. package/dist/stock.js +77 -0
  112. package/dist/stock.js.map +1 -0
  113. package/dist/tenant.d.ts +69 -0
  114. package/dist/tenant.d.ts.map +1 -0
  115. package/dist/tenant.js +68 -0
  116. package/dist/tenant.js.map +1 -0
  117. package/dist/token-store.d.ts +16 -0
  118. package/dist/token-store.d.ts.map +1 -0
  119. package/dist/token-store.js +47 -0
  120. package/dist/token-store.js.map +1 -0
  121. package/dist/tools.d.ts +201 -0
  122. package/dist/tools.d.ts.map +1 -0
  123. package/dist/tools.js +779 -0
  124. package/dist/tools.js.map +1 -0
  125. package/dist/webhooks.d.ts +30 -0
  126. package/dist/webhooks.d.ts.map +1 -0
  127. package/dist/webhooks.js +69 -0
  128. package/dist/webhooks.js.map +1 -0
  129. package/package.json +53 -0
package/dist/config.js ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * One storefront's identity, vocabulary and shop wiring.
3
+ *
4
+ * The single-tenant connector this grew out of held all of it as literals:
5
+ * 'Moody Lenses', 'https://moodycosmetics.com', `list_moody_lenses`. That reads
6
+ * fine until there is a second merchant, at which point the only way to add one
7
+ * is to copy 2,443 lines and rename 172 strings — and then fix every bug twice.
8
+ *
9
+ * What is NOT here is as deliberate as what is. The product model stays generic
10
+ * Shopify: no per-merchant fields, no category enums. The moment a merchant
11
+ * needs a bespoke field, it belongs in their Shopify metafields, not in this
12
+ * type.
13
+ */
14
+ export const vocabulary = (config) => ({
15
+ merchant: config.server.title,
16
+ noun: config.naming?.noun ?? 'product',
17
+ nounPlural: config.naming?.nounPlural ?? `${config.naming?.noun ?? 'product'}s`,
18
+ hints: {
19
+ browse: config.hints?.browse ?? '',
20
+ product: config.hints?.product ?? '',
21
+ checkout: config.hints?.checkout ?? '',
22
+ example: config.hints?.example ?? '',
23
+ },
24
+ });
25
+ /**
26
+ * `prefix` and `noun` are woven into identifiers, so anything that is not
27
+ * `[a-z0-9_]` would produce a tool name a host may reject outright. Sanitised
28
+ * rather than rejected: a merchant called "Els-Pet" should not fail to boot
29
+ * over a hyphen.
30
+ */
31
+ const slug = (s) => s
32
+ .toLowerCase()
33
+ .replace(/[^a-z0-9]+/g, '_')
34
+ .replace(/^_+|_+$/g, '');
35
+ export const toolNames = (config) => {
36
+ const prefix = config.naming?.prefix ? slug(config.naming.prefix) : '';
37
+ const noun = slug(config.naming?.noun ?? 'product');
38
+ const plural = slug(config.naming?.nounPlural ?? `${noun}s`);
39
+ const p = prefix ? `${prefix}_` : '';
40
+ return {
41
+ list: `list_${p}${plural}`,
42
+ get: `get_${p}${noun}`,
43
+ checkout: `create_${p}checkout`,
44
+ lookupOrder: `lookup_${p}order`,
45
+ };
46
+ };
47
+ const bare = (u) => u.replace(/\/$/, '');
48
+ export const resolveStorefront = (config) => {
49
+ const appUrl = bare(config.urls.appUrl);
50
+ return {
51
+ config,
52
+ tools: toolNames(config),
53
+ vocab: vocabulary(config),
54
+ appUrl,
55
+ publicUrl: bare(config.urls.publicUrl ?? appUrl),
56
+ // Fixed by the code, not the merchant: it is registered with Shopify as an
57
+ // allowed redirection URL, and a config that could drift from what was
58
+ // registered would fail only at install time, on someone else's screen.
59
+ redirectUri: `${appUrl}/auth/callback`,
60
+ scopes: config.shopify.scopes ?? 'read_products,read_orders,read_discounts',
61
+ tokenPath: config.shopify.tokenPath ?? `/app/data/${config.id}-token.json`,
62
+ cardUriPrefix: `ui://${config.id}/`,
63
+ };
64
+ };
65
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA+GH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAwB,EAAc,EAAE,CAAC,CAAC;IACnE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;IAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,IAAI,SAAS;IACtC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,IAAI,SAAS,GAAG;IAC/E,KAAK,EAAE;QACL,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE;QAClC,OAAO,EAAE,MAAM,CAAC,KAAK,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AAsB,EAAE;IAChF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO;QACL,MAAM;QACN,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC;QACxB,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC;QACzB,MAAM;QACN,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC;QAChD,2EAA2E;QAC3E,uEAAuE;QACvE,wEAAwE;QACxE,WAAW,EAAE,GAAG,MAAM,gBAAgB;QACtC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,0CAA0C;QAC3E,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,aAAa,MAAM,CAAC,EAAE,aAAa;QAC1E,aAAa,EAAE,QAAQ,MAAM,CAAC,EAAE,GAAG;KACpC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shopify says 401 for a revoked or expired token and 403 for one whose scopes
3
+ * no longer cover the call. Both mean "these credentials are no longer good",
4
+ * which is the merchant's to fix. Anything else — 500, 429, a network blip — is
5
+ * ours, and sending them off to reauthorise over it is pointless work.
6
+ */
7
+ export declare const credentialsRejected: (lastError: string | undefined) => boolean;
8
+ /** No token at all, or one that is being refused. */
9
+ export declare const needsAuth: (connected: boolean, lastError: string | undefined) => boolean;
10
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,WAAW,MAAM,GAAG,SAAS,KAAG,OAC7B,CAAC;AAExC,qDAAqD;AACrD,eAAO,MAAM,SAAS,GAAI,WAAW,OAAO,EAAE,WAAW,MAAM,GAAG,SAAS,KAAG,OAChC,CAAC"}
@@ -0,0 +1,21 @@
1
+ // Is this store connected, and does the merchant have to do something about it?
2
+ //
3
+ // Three states, not two — and conflating two of them locked a merchant out of
4
+ // fixing the third. Reinstalling the app elsewhere REVOKES the access token we
5
+ // hold; ours started answering 401, but "connected" was computed from "a token
6
+ // file exists", so the status page kept saying Connected and the branch that
7
+ // auto-starts OAuth kept skipping. They approved the app, came back, and were
8
+ // told by the one page that could have helped that nothing was wrong.
9
+ //
10
+ // Its own module because `index.ts` starts a server on import, so nothing there
11
+ // can be unit-tested — and this is exactly the logic that has to be.
12
+ /**
13
+ * Shopify says 401 for a revoked or expired token and 403 for one whose scopes
14
+ * no longer cover the call. Both mean "these credentials are no longer good",
15
+ * which is the merchant's to fix. Anything else — 500, 429, a network blip — is
16
+ * ours, and sending them off to reauthorise over it is pointless work.
17
+ */
18
+ export const credentialsRejected = (lastError) => /HTTP 40[13]\b/.test(lastError ?? '');
19
+ /** No token at all, or one that is being refused. */
20
+ export const needsAuth = (connected, lastError) => !connected || credentialsRejected(lastError);
21
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,gFAAgF;AAChF,qEAAqE;AAErE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,SAA6B,EAAW,EAAE,CAC5E,eAAe,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;AAExC,qDAAqD;AACrD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAAkB,EAAE,SAA6B,EAAW,EAAE,CACtF,CAAC,SAAS,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}