@fmaplabs/shopify-app-convex-session-storage 0.1.0 → 0.1.2
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 +171 -15
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/session-storage.d.ts +51 -0
- package/dist/client/session-storage.d.ts.map +1 -0
- package/dist/client/session-storage.js +71 -0
- package/dist/client/session-storage.js.map +1 -0
- package/package.json +105 -95
- package/src/client/index.ts +5 -0
- package/src/client/session-storage.test.ts +210 -0
- package/src/client/session-storage.ts +120 -0
- package/LICENSE +0 -201
package/README.md
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/@fmaplabs%2Fshopify-app-convex-session-storage)
|
|
4
4
|
|
|
5
|
-
A [Convex component](https://docs.convex.dev/components) that provides Shopify
|
|
5
|
+
A [Convex component](https://docs.convex.dev/components) that provides Shopify
|
|
6
|
+
session storage backed by a Convex database. Drop-in session persistence for
|
|
7
|
+
Shopify apps built on Convex.
|
|
6
8
|
|
|
7
|
-
Found a bug? Feature request?
|
|
9
|
+
Found a bug? Feature request?
|
|
10
|
+
[File it here](https://github.com/fmaplabs/shopify-app-convex-session-storage/issues).
|
|
8
11
|
|
|
9
12
|
## Installation
|
|
10
13
|
|
|
@@ -26,9 +29,18 @@ export default app;
|
|
|
26
29
|
|
|
27
30
|
## Usage
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
This package provides two ways to interact with session storage:
|
|
33
|
+
|
|
34
|
+
- **`ShopifySessionClient`** — for use _inside_ Convex functions (server-side, via `ctx.runQuery`/`ctx.runMutation`)
|
|
35
|
+
- **`ConvexSessionStorage`** — for use _outside_ Convex (your web server), implementing Shopify's [`SessionStorage`](https://github.com/Shopify/shopify-app-js/tree/main/packages/apps/session-storage/shopify-app-session-storage) interface
|
|
36
|
+
|
|
37
|
+
### Step 1: Expose session functions in your Convex backend
|
|
38
|
+
|
|
39
|
+
The component's internal functions can't be called over HTTP directly. Create
|
|
40
|
+
public wrappers in your Convex backend using `ShopifySessionClient`:
|
|
30
41
|
|
|
31
42
|
```ts
|
|
43
|
+
// convex/sessions.ts
|
|
32
44
|
import { mutation, query } from "./_generated/server.js";
|
|
33
45
|
import { components } from "./_generated/api.js";
|
|
34
46
|
import { ShopifySessionClient } from "@fmaplabs/shopify-app-convex-session-storage";
|
|
@@ -42,9 +54,27 @@ export const storeSession = mutation({
|
|
|
42
54
|
args: {
|
|
43
55
|
id: v.string(),
|
|
44
56
|
shop: v.string(),
|
|
57
|
+
state: v.optional(v.string()),
|
|
45
58
|
isOnline: v.boolean(),
|
|
46
59
|
scope: v.optional(v.string()),
|
|
60
|
+
expires: v.optional(v.string()),
|
|
47
61
|
accessToken: v.optional(v.string()),
|
|
62
|
+
onlineAccessInfo: v.optional(
|
|
63
|
+
v.object({
|
|
64
|
+
expires_in: v.number(),
|
|
65
|
+
associated_user_scope: v.string(),
|
|
66
|
+
associated_user: v.object({
|
|
67
|
+
id: v.number(),
|
|
68
|
+
first_name: v.string(),
|
|
69
|
+
last_name: v.string(),
|
|
70
|
+
email: v.string(),
|
|
71
|
+
email_verified: v.boolean(),
|
|
72
|
+
account_owner: v.boolean(),
|
|
73
|
+
locale: v.string(),
|
|
74
|
+
collaborator: v.boolean(),
|
|
75
|
+
}),
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
48
78
|
},
|
|
49
79
|
handler: async (ctx, args) => {
|
|
50
80
|
return await sessionClient.storeSession(ctx, args);
|
|
@@ -64,25 +94,126 @@ export const deleteSession = mutation({
|
|
|
64
94
|
return await sessionClient.deleteSession(ctx, args);
|
|
65
95
|
},
|
|
66
96
|
});
|
|
97
|
+
|
|
98
|
+
export const deleteSessions = mutation({
|
|
99
|
+
args: { ids: v.array(v.string()) },
|
|
100
|
+
handler: async (ctx, args) => {
|
|
101
|
+
return await sessionClient.deleteSessions(ctx, args);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const findSessionsByShop = query({
|
|
106
|
+
args: { shop: v.string() },
|
|
107
|
+
handler: async (ctx, args) => {
|
|
108
|
+
return await sessionClient.findSessionsByShop(ctx, args);
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
See [example/convex/example.ts](./example/convex/example.ts) for a complete
|
|
114
|
+
example with additional helper functions.
|
|
115
|
+
|
|
116
|
+
### Step 2: Use `ConvexSessionStorage` in your web server
|
|
117
|
+
|
|
118
|
+
Pass `ConvexSessionStorage` to Shopify's `shopifyApp()` as the session storage
|
|
119
|
+
adapter. It calls the public Convex functions you created above over HTTP.
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
npm install @shopify/shopify-api
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### With `ConvexHttpClient`
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { ConvexSessionStorage } from "@fmaplabs/shopify-app-convex-session-storage";
|
|
129
|
+
import { ConvexHttpClient } from "convex/browser";
|
|
130
|
+
import { api } from "../convex/_generated/api.js";
|
|
131
|
+
|
|
132
|
+
const client = new ConvexHttpClient(process.env.CONVEX_URL!);
|
|
133
|
+
|
|
134
|
+
export const sessionStorage = new ConvexSessionStorage(client, {
|
|
135
|
+
storeSession: api.sessions.storeSession,
|
|
136
|
+
loadSession: api.sessions.loadSession,
|
|
137
|
+
deleteSession: api.sessions.deleteSession,
|
|
138
|
+
deleteSessions: api.sessions.deleteSessions,
|
|
139
|
+
findSessionsByShop: api.sessions.findSessionsByShop,
|
|
140
|
+
});
|
|
67
141
|
```
|
|
68
142
|
|
|
69
|
-
|
|
143
|
+
#### With Next.js `fetchQuery`/`fetchMutation`
|
|
144
|
+
|
|
145
|
+
`ConvexSessionStorage` accepts any object with `query()` and `mutation()`
|
|
146
|
+
methods, so you can wrap Convex's Next.js helpers:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { ConvexSessionStorage } from "@fmaplabs/shopify-app-convex-session-storage";
|
|
150
|
+
import { fetchQuery, fetchMutation } from "convex/nextjs";
|
|
151
|
+
import { api } from "../convex/_generated/api.js";
|
|
152
|
+
|
|
153
|
+
const client = {
|
|
154
|
+
query: (name: any, args: any) => fetchQuery(name, args),
|
|
155
|
+
mutation: (name: any, args: any) => fetchMutation(name, args),
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const sessionStorage = new ConvexSessionStorage(client, {
|
|
159
|
+
storeSession: api.sessions.storeSession,
|
|
160
|
+
loadSession: api.sessions.loadSession,
|
|
161
|
+
deleteSession: api.sessions.deleteSession,
|
|
162
|
+
deleteSessions: api.sessions.deleteSessions,
|
|
163
|
+
findSessionsByShop: api.sessions.findSessionsByShop,
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### With `shopifyApp()`
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import shopify from "@shopify/shopify-app-remix"; // or @shopify/shopify-app-express
|
|
171
|
+
import { sessionStorage } from "./session-storage";
|
|
172
|
+
|
|
173
|
+
const shopifyApp = shopify({
|
|
174
|
+
// ...other config
|
|
175
|
+
sessionStorage,
|
|
176
|
+
});
|
|
177
|
+
```
|
|
70
178
|
|
|
71
179
|
## API
|
|
72
180
|
|
|
73
181
|
### `ShopifySessionClient`
|
|
74
182
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
183
|
+
For use inside Convex functions. Wraps the component's internal queries and
|
|
184
|
+
mutations.
|
|
185
|
+
|
|
186
|
+
| Method | Type | Description |
|
|
187
|
+
| ---------------------------------------- | -------- | ----------------------------------- |
|
|
188
|
+
| `loadSession(ctx, { id })` | query | Load a session by ID |
|
|
189
|
+
| `storeSession(ctx, session)` | mutation | Create or update a session (upsert) |
|
|
190
|
+
| `deleteSession(ctx, { id })` | mutation | Delete a session by ID |
|
|
191
|
+
| `deleteSessions(ctx, { ids })` | mutation | Delete multiple sessions by ID |
|
|
192
|
+
| `findSessionsByShop(ctx, { shop })` | query | Find all sessions for a shop |
|
|
193
|
+
| `getOfflineSessionByShop(ctx, { shop })` | query | Get the offline session for a shop |
|
|
194
|
+
| `deleteSessionsByShop(ctx, { shop })` | mutation | Delete all sessions for a shop |
|
|
195
|
+
| `cleanupExpiredSessions(ctx)` | mutation | Delete all expired sessions |
|
|
196
|
+
| `updateScopes(ctx, { id, scope })` | mutation | Update scopes on a session |
|
|
197
|
+
|
|
198
|
+
### `ConvexSessionStorage`
|
|
199
|
+
|
|
200
|
+
For use outside Convex (web server). Implements Shopify's `SessionStorage`
|
|
201
|
+
interface.
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
new ConvexSessionStorage(client, functionRefs);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
- **`client`** — any object with `query(name, args)` and `mutation(name, args)` methods (e.g. `ConvexHttpClient`)
|
|
208
|
+
- **`functionRefs`** — references to your 5 public Convex functions: `storeSession`, `loadSession`, `deleteSession`, `deleteSessions`, `findSessionsByShop`
|
|
209
|
+
|
|
210
|
+
| Method | Description |
|
|
211
|
+
| -------------------------- | ---------------------------------------- |
|
|
212
|
+
| `storeSession(session)` | Store a Shopify `Session` object |
|
|
213
|
+
| `loadSession(id)` | Load a session, returns `Session` or `undefined` |
|
|
214
|
+
| `deleteSession(id)` | Delete a session by ID |
|
|
215
|
+
| `deleteSessions(ids)` | Delete multiple sessions by ID |
|
|
216
|
+
| `findSessionsByShop(shop)` | Find all sessions for a shop |
|
|
86
217
|
|
|
87
218
|
### Types
|
|
88
219
|
|
|
@@ -92,6 +223,8 @@ import type {
|
|
|
92
223
|
ShopifySessionInput,
|
|
93
224
|
OnlineAccessInfo,
|
|
94
225
|
AssociatedUser,
|
|
226
|
+
ConvexSessionClient,
|
|
227
|
+
SessionFunctionRefs,
|
|
95
228
|
} from "@fmaplabs/shopify-app-convex-session-storage";
|
|
96
229
|
```
|
|
97
230
|
|
|
@@ -107,3 +240,26 @@ Run tests:
|
|
|
107
240
|
```sh
|
|
108
241
|
npm test
|
|
109
242
|
```
|
|
243
|
+
|
|
244
|
+
### License
|
|
245
|
+
|
|
246
|
+
MIT License
|
|
247
|
+
|
|
248
|
+
Copyright (c) 2026 fmap labs
|
|
249
|
+
|
|
250
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
251
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
252
|
+
the Software without restriction, including without limitation the rights to
|
|
253
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
254
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
255
|
+
subject to the following conditions:
|
|
256
|
+
|
|
257
|
+
The above copyright notice and this permission notice shall be included in all
|
|
258
|
+
copies or substantial portions of the Software.
|
|
259
|
+
|
|
260
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
261
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
262
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
263
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
264
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
265
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
|
|
2
2
|
import type { ComponentApi } from "../component/_generated/component.js";
|
|
3
3
|
export type { ComponentApi };
|
|
4
|
+
export { ConvexSessionStorage, type ConvexSessionClient, type SessionFunctionRefs, } from "./session-storage.js";
|
|
4
5
|
export type AssociatedUser = {
|
|
5
6
|
id: number;
|
|
6
7
|
first_name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEzE,YAAY,EAAE,YAAY,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEzE,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GACzB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,cAAc,CAAC;C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B,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GACnB,OAAO,CAAC,OAAO,CAAC;IAIb,cAAc,CAClB,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,EAAE,CAAA;KAAE,GACtB,OAAO,CAAC,OAAO,CAAC;IAIb,kBAAkB,CACtB,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GACrB,OAAO,CAAC,cAAc,EAAE,CAAC;IAItB,uBAAuB,CAC3B,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GACrB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAO3B,oBAAoB,CACxB,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GACrB,OAAO,CAAC,IAAI,CAAC;IAIV,sBAAsB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD,YAAY,CAChB,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAClC,OAAO,CAAC,OAAO,CAAC;CAGpB"}
|
package/dist/client/index.js
CHANGED
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,oBAAoB,GAGrB,MAAM,sBAAsB,CAAC;AAiD9B,MAAM,OAAO,oBAAoB;IACZ;IAAnB,YAAmB,SAAuB;QAAvB,cAAS,GAAT,SAAS,CAAc;IAAG,CAAC;IAE9C,KAAK,CAAC,WAAW,CACf,GAAa,EACb,IA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AAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,GAAgB,EAChB,IAAmC;QAEnC,OAAO,MAAM,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Session } from "@shopify/shopify-api";
|
|
2
|
+
import type { SessionStorage } from "@shopify/shopify-app-session-storage";
|
|
3
|
+
/**
|
|
4
|
+
* Minimal client contract compatible with ConvexHttpClient, fetchQuery/fetchMutation wrappers,
|
|
5
|
+
* or any custom implementation.
|
|
6
|
+
*/
|
|
7
|
+
export interface ConvexSessionClient {
|
|
8
|
+
query<Output>(name: string | {
|
|
9
|
+
_returnType: Output;
|
|
10
|
+
}, args: Record<string, unknown>): Promise<Output>;
|
|
11
|
+
mutation<Output>(name: string | {
|
|
12
|
+
_returnType: Output;
|
|
13
|
+
}, args: Record<string, unknown>): Promise<Output>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* References to the consumer's public Convex functions that wrap the component's
|
|
17
|
+
* internal session CRUD operations.
|
|
18
|
+
*/
|
|
19
|
+
export interface SessionFunctionRefs {
|
|
20
|
+
storeSession: string | {
|
|
21
|
+
_returnType: unknown;
|
|
22
|
+
_args: unknown;
|
|
23
|
+
};
|
|
24
|
+
loadSession: string | {
|
|
25
|
+
_returnType: unknown;
|
|
26
|
+
_args: unknown;
|
|
27
|
+
};
|
|
28
|
+
deleteSession: string | {
|
|
29
|
+
_returnType: unknown;
|
|
30
|
+
_args: unknown;
|
|
31
|
+
};
|
|
32
|
+
deleteSessions: string | {
|
|
33
|
+
_returnType: unknown;
|
|
34
|
+
_args: unknown;
|
|
35
|
+
};
|
|
36
|
+
findSessionsByShop: string | {
|
|
37
|
+
_returnType: unknown;
|
|
38
|
+
_args: unknown;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export declare class ConvexSessionStorage implements SessionStorage {
|
|
42
|
+
private client;
|
|
43
|
+
private fns;
|
|
44
|
+
constructor(client: ConvexSessionClient, fns: SessionFunctionRefs);
|
|
45
|
+
storeSession(session: Session): Promise<boolean>;
|
|
46
|
+
loadSession(id: string): Promise<Session | undefined>;
|
|
47
|
+
deleteSession(id: string): Promise<boolean>;
|
|
48
|
+
deleteSessions(ids: string[]): Promise<boolean>;
|
|
49
|
+
findSessionsByShop(shop: string): Promise<Session[]>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=session-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-storage.d.ts","sourceRoot":"","sources":["../../src/client/session-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAG3E;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,MAAM,EACV,IAAI,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,EACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,QAAQ,CAAC,MAAM,EACb,IAAI,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,EACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IAChE,WAAW,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IAC/D,aAAa,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IACjE,cAAc,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IAClE,kBAAkB,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;CACvE;AAiDD,qBAAa,oBAAqB,YAAW,cAAc;IAEvD,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,GAAG;gBADH,MAAM,EAAE,mBAAmB,EAC3B,GAAG,EAAE,mBAAmB;IAG5B,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAKhD,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IASrD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAO/C,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAO3D"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Session } from "@shopify/shopify-api";
|
|
2
|
+
function sessionToInput(session) {
|
|
3
|
+
return {
|
|
4
|
+
id: session.id,
|
|
5
|
+
shop: session.shop,
|
|
6
|
+
state: session.state,
|
|
7
|
+
isOnline: session.isOnline,
|
|
8
|
+
scope: session.scope,
|
|
9
|
+
expires: session.expires ? session.expires.toISOString() : undefined,
|
|
10
|
+
accessToken: session.accessToken,
|
|
11
|
+
onlineAccessInfo: session.onlineAccessInfo?.associated_user
|
|
12
|
+
? {
|
|
13
|
+
expires_in: session.onlineAccessInfo.expires_in,
|
|
14
|
+
associated_user_scope: session.onlineAccessInfo.associated_user_scope,
|
|
15
|
+
associated_user: {
|
|
16
|
+
id: session.onlineAccessInfo.associated_user.id,
|
|
17
|
+
first_name: session.onlineAccessInfo.associated_user.first_name,
|
|
18
|
+
last_name: session.onlineAccessInfo.associated_user.last_name,
|
|
19
|
+
email: session.onlineAccessInfo.associated_user.email,
|
|
20
|
+
email_verified: session.onlineAccessInfo.associated_user.email_verified,
|
|
21
|
+
account_owner: session.onlineAccessInfo.associated_user.account_owner,
|
|
22
|
+
locale: session.onlineAccessInfo.associated_user.locale,
|
|
23
|
+
collaborator: session.onlineAccessInfo.associated_user.collaborator,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
: undefined,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function dataToSession(data) {
|
|
30
|
+
return new Session({
|
|
31
|
+
id: data.id,
|
|
32
|
+
shop: data.shop,
|
|
33
|
+
state: data.state ?? "",
|
|
34
|
+
isOnline: data.isOnline,
|
|
35
|
+
scope: data.scope,
|
|
36
|
+
expires: data.expires ? new Date(data.expires) : undefined,
|
|
37
|
+
accessToken: data.accessToken,
|
|
38
|
+
onlineAccessInfo: data.onlineAccessInfo,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// TODO: Implement the ConvexSessionStorage class
|
|
42
|
+
// See the plan description above for guidance on the 5 required SessionStorage methods.
|
|
43
|
+
export class ConvexSessionStorage {
|
|
44
|
+
client;
|
|
45
|
+
fns;
|
|
46
|
+
constructor(client, fns) {
|
|
47
|
+
this.client = client;
|
|
48
|
+
this.fns = fns;
|
|
49
|
+
}
|
|
50
|
+
async storeSession(session) {
|
|
51
|
+
await this.client.mutation(this.fns.storeSession, sessionToInput(session));
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
async loadSession(id) {
|
|
55
|
+
const data = await this.client.query(this.fns.loadSession, { id });
|
|
56
|
+
if (!data)
|
|
57
|
+
return undefined;
|
|
58
|
+
return dataToSession(data);
|
|
59
|
+
}
|
|
60
|
+
async deleteSession(id) {
|
|
61
|
+
return await this.client.mutation(this.fns.deleteSession, { id });
|
|
62
|
+
}
|
|
63
|
+
async deleteSessions(ids) {
|
|
64
|
+
return await this.client.mutation(this.fns.deleteSessions, { ids });
|
|
65
|
+
}
|
|
66
|
+
async findSessionsByShop(shop) {
|
|
67
|
+
const sessions = await this.client.query(this.fns.findSessionsByShop, { shop });
|
|
68
|
+
return sessions.map(dataToSession);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=session-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-storage.js","sourceRoot":"","sources":["../../src/client/session-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AA+B/C,SAAS,cAAc,CAAC,OAAgB;IACtC,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;QACpE,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,eAAe;YACzD,CAAC,CAAC;gBACE,UAAU,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU;gBAC/C,qBAAqB,EACnB,OAAO,CAAC,gBAAgB,CAAC,qBAAqB;gBAChD,eAAe,EAAE;oBACf,EAAE,EAAE,OAAO,CAAC,gBAAgB,CAAC,eAAe,CAAC,EAAE;oBAC/C,UAAU,EAAE,OAA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|
15
|
-
"session-storage"
|
|
16
|
-
],
|
|
17
|
-
"type": "module",
|
|
18
|
-
"publishConfig": {
|
|
19
|
-
"access": "public"
|
|
20
|
-
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"dev": "run-p -r 'dev:*'",
|
|
23
|
-
"dev:backend": "convex dev --typecheck-components",
|
|
24
|
-
"dev:frontend": "cd example && vite --clearScreen false",
|
|
25
|
-
"dev:build": "chokidar 'tsconfig*.json' 'src/**/*.ts' -i '**/*.test.ts' -c 'npm run build:codegen' --initial",
|
|
26
|
-
"predev": "path-exists .env.local dist || (npm run build && convex dev --once)",
|
|
27
|
-
"build": "tsc --project ./tsconfig.build.json",
|
|
28
|
-
"build:codegen": "npx convex codegen --component-dir ./src/component && npm run build",
|
|
29
|
-
"build:clean": "rm -rf dist *.tsbuildinfo && npm run build:codegen",
|
|
30
|
-
"typecheck": "tsc --noEmit && tsc -p example && tsc -p example/convex",
|
|
31
|
-
"lint": "eslint .",
|
|
32
|
-
"all": "run-p -r 'dev:*' 'test:watch'",
|
|
33
|
-
"test": "vitest run --typecheck",
|
|
34
|
-
"test:watch": "vitest --typecheck --clearScreen false",
|
|
35
|
-
"test:debug": "vitest --inspect-brk --no-file-parallelism",
|
|
36
|
-
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
37
|
-
"preversion": "npm ci && npm run build:clean && run-p test lint typecheck",
|
|
38
|
-
"prepublishOnly": "npm whoami || npm login",
|
|
39
|
-
"alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
|
|
40
|
-
"release": "npm version patch && npm publish && git push --follow-tags",
|
|
41
|
-
"version": "vim -c 'normal o' -c 'normal o## '$npm_package_version CHANGELOG.md && prettier -w CHANGELOG.md && git add CHANGELOG.md"
|
|
42
|
-
},
|
|
43
|
-
"files": [
|
|
44
|
-
"dist",
|
|
45
|
-
"src"
|
|
46
|
-
],
|
|
47
|
-
"exports": {
|
|
48
|
-
"./package.json": "./package.json",
|
|
49
|
-
".": {
|
|
50
|
-
"types": "./dist/client/index.d.ts",
|
|
51
|
-
"default": "./dist/client/index.js"
|
|
2
|
+
"name": "@fmaplabs/shopify-app-convex-session-storage",
|
|
3
|
+
"description": "Shopify session storage backed by Convex, as a Convex component.",
|
|
4
|
+
"repository": "github:fmaplabs/shopify-app-convex-session-storage",
|
|
5
|
+
"homepage": "https://github.com/fmaplabs/shopify-app-convex-session-storage#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/fmaplabs/shopify-app-convex-session-storage/issues"
|
|
52
8
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
9
|
+
"version": "0.1.2",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"convex",
|
|
13
|
+
"component",
|
|
14
|
+
"shopify",
|
|
15
|
+
"session-storage"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
56
20
|
},
|
|
57
|
-
"
|
|
58
|
-
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "run-p -r 'dev:*'",
|
|
23
|
+
"dev:backend": "convex dev --typecheck-components",
|
|
24
|
+
"dev:frontend": "cd example && vite --clearScreen false",
|
|
25
|
+
"dev:build": "chokidar 'tsconfig*.json' 'src/**/*.ts' -i '**/*.test.ts' -c 'npm run build:codegen' --initial",
|
|
26
|
+
"predev": "path-exists .env.local dist || (npm run build && convex dev --once)",
|
|
27
|
+
"build": "tsc --project ./tsconfig.build.json",
|
|
28
|
+
"build:codegen": "npx convex codegen --component-dir ./src/component && npm run build",
|
|
29
|
+
"build:clean": "rm -rf dist *.tsbuildinfo && npm run build:codegen",
|
|
30
|
+
"typecheck": "tsc --noEmit && tsc -p example && tsc -p example/convex",
|
|
31
|
+
"lint": "eslint .",
|
|
32
|
+
"all": "run-p -r 'dev:*' 'test:watch'",
|
|
33
|
+
"test": "vitest run --typecheck",
|
|
34
|
+
"test:watch": "vitest --typecheck --clearScreen false",
|
|
35
|
+
"test:debug": "vitest --inspect-brk --no-file-parallelism",
|
|
36
|
+
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
37
|
+
"preversion": "npm ci && npm run build:clean && run-p test lint typecheck",
|
|
38
|
+
"prepublishOnly": "npm whoami || npm login",
|
|
39
|
+
"alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
|
|
40
|
+
"release": "npm version patch && npm publish && git push --follow-tags",
|
|
41
|
+
"version": "vim -c 'normal o' -c 'normal o## '$npm_package_version CHANGELOG.md && prettier -w CHANGELOG.md && git add CHANGELOG.md"
|
|
59
42
|
},
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"src"
|
|
46
|
+
],
|
|
47
|
+
"exports": {
|
|
48
|
+
"./package.json": "./package.json",
|
|
49
|
+
".": {
|
|
50
|
+
"types": "./dist/client/index.d.ts",
|
|
51
|
+
"default": "./dist/client/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./test": "./src/test.ts",
|
|
54
|
+
"./_generated/component.js": {
|
|
55
|
+
"types": "./dist/component/_generated/component.d.ts"
|
|
56
|
+
},
|
|
57
|
+
"./_generated/component": {
|
|
58
|
+
"types": "./dist/component/_generated/component.d.ts"
|
|
59
|
+
},
|
|
60
|
+
"./convex.config.js": {
|
|
61
|
+
"types": "./dist/component/convex.config.d.ts",
|
|
62
|
+
"default": "./dist/component/convex.config.js"
|
|
63
|
+
},
|
|
64
|
+
"./convex.config": {
|
|
65
|
+
"types": "./dist/component/convex.config.d.ts",
|
|
66
|
+
"default": "./dist/component/convex.config.js"
|
|
67
|
+
}
|
|
63
68
|
},
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"convex": "^1.31.7",
|
|
71
|
+
"@shopify/shopify-api": "^12.0.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependenciesMeta": {
|
|
74
|
+
"@shopify/shopify-api": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@convex-dev/eslint-plugin": "^1.1.1",
|
|
80
|
+
"@edge-runtime/vm": "^5.0.0",
|
|
81
|
+
"@eslint/eslintrc": "^3.3.3",
|
|
82
|
+
"@eslint/js": "9.39.2",
|
|
83
|
+
"@shopify/shopify-api": "^12.3.0",
|
|
84
|
+
"@types/node": "^24.10.11",
|
|
85
|
+
"@types/react": "^19.2.13",
|
|
86
|
+
"@types/react-dom": "^19.2.3",
|
|
87
|
+
"@vitejs/plugin-react": "^5.1.3",
|
|
88
|
+
"chokidar-cli": "3.0.0",
|
|
89
|
+
"convex": "1.31.7",
|
|
90
|
+
"convex-test": "0.0.41",
|
|
91
|
+
"eslint": "9.39.2",
|
|
92
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
93
|
+
"eslint-plugin-react-refresh": "^0.5.0",
|
|
94
|
+
"globals": "^17.3.0",
|
|
95
|
+
"npm-run-all2": "8.0.4",
|
|
96
|
+
"path-exists-cli": "2.0.0",
|
|
97
|
+
"pkg-pr-new": "^0.0.63",
|
|
98
|
+
"prettier": "3.8.1",
|
|
99
|
+
"react": "^19.2.4",
|
|
100
|
+
"react-dom": "^19.2.4",
|
|
101
|
+
"typescript": "5.9.3",
|
|
102
|
+
"typescript-eslint": "8.54.0",
|
|
103
|
+
"vite": "7.3.1",
|
|
104
|
+
"vitest": "4.0.18"
|
|
105
|
+
},
|
|
106
|
+
"types": "./dist/client/index.d.ts",
|
|
107
|
+
"module": "./dist/client/index.js",
|
|
108
|
+
"dependencies": {
|
|
109
|
+
"@shopify/shopify-app-session-storage": "^4.0.5"
|
|
67
110
|
}
|
|
68
|
-
|
|
69
|
-
"peerDependencies": {
|
|
70
|
-
"convex": "^1.31.7"
|
|
71
|
-
},
|
|
72
|
-
"devDependencies": {
|
|
73
|
-
"@convex-dev/eslint-plugin": "^1.1.1",
|
|
74
|
-
"@edge-runtime/vm": "^5.0.0",
|
|
75
|
-
"@eslint/eslintrc": "^3.3.3",
|
|
76
|
-
"@eslint/js": "9.39.2",
|
|
77
|
-
"@types/node": "^24.10.11",
|
|
78
|
-
"@types/react": "^19.2.13",
|
|
79
|
-
"@types/react-dom": "^19.2.3",
|
|
80
|
-
"@vitejs/plugin-react": "^5.1.3",
|
|
81
|
-
"chokidar-cli": "3.0.0",
|
|
82
|
-
"convex": "1.31.7",
|
|
83
|
-
"convex-test": "0.0.41",
|
|
84
|
-
"eslint": "9.39.2",
|
|
85
|
-
"eslint-plugin-react-hooks": "^7.0.1",
|
|
86
|
-
"eslint-plugin-react-refresh": "^0.5.0",
|
|
87
|
-
"globals": "^17.3.0",
|
|
88
|
-
"npm-run-all2": "8.0.4",
|
|
89
|
-
"path-exists-cli": "2.0.0",
|
|
90
|
-
"pkg-pr-new": "^0.0.63",
|
|
91
|
-
"prettier": "3.8.1",
|
|
92
|
-
"react": "^19.2.4",
|
|
93
|
-
"react-dom": "^19.2.4",
|
|
94
|
-
"typescript": "5.9.3",
|
|
95
|
-
"typescript-eslint": "8.54.0",
|
|
96
|
-
"vite": "7.3.1",
|
|
97
|
-
"vitest": "4.0.18"
|
|
98
|
-
},
|
|
99
|
-
"types": "./dist/client/index.d.ts",
|
|
100
|
-
"module": "./dist/client/index.js"
|
|
101
|
-
}
|
|
111
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -6,6 +6,11 @@ import type {
|
|
|
6
6
|
import type { ComponentApi } from "../component/_generated/component.js";
|
|
7
7
|
|
|
8
8
|
export type { ComponentApi };
|
|
9
|
+
export {
|
|
10
|
+
ConvexSessionStorage,
|
|
11
|
+
type ConvexSessionClient,
|
|
12
|
+
type SessionFunctionRefs,
|
|
13
|
+
} from "./session-storage.js";
|
|
9
14
|
|
|
10
15
|
export type AssociatedUser = {
|
|
11
16
|
id: number;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
|
+
import { Session } from "@shopify/shopify-api";
|
|
3
|
+
import {
|
|
4
|
+
ConvexSessionStorage,
|
|
5
|
+
type ConvexSessionClient,
|
|
6
|
+
} from "./session-storage.js";
|
|
7
|
+
import type { ShopifySession } from "./index.js";
|
|
8
|
+
|
|
9
|
+
function createMockClient() {
|
|
10
|
+
return {
|
|
11
|
+
query: vi.fn(),
|
|
12
|
+
mutation: vi.fn(),
|
|
13
|
+
} satisfies ConvexSessionClient;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const fns = {
|
|
17
|
+
storeSession: "sessions:storeSession",
|
|
18
|
+
loadSession: "sessions:loadSession",
|
|
19
|
+
deleteSession: "sessions:deleteSession",
|
|
20
|
+
deleteSessions: "sessions:deleteSessions",
|
|
21
|
+
findSessionsByShop: "sessions:findSessionsByShop",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe("ConvexSessionStorage", () => {
|
|
25
|
+
test("storeSession converts Date to ISO string", async () => {
|
|
26
|
+
const client = createMockClient();
|
|
27
|
+
client.mutation.mockResolvedValue(null);
|
|
28
|
+
const storage = new ConvexSessionStorage(client, fns);
|
|
29
|
+
|
|
30
|
+
const expires = new Date("2025-06-01T00:00:00.000Z");
|
|
31
|
+
const session = new Session({
|
|
32
|
+
id: "offline_shop.myshopify.com",
|
|
33
|
+
shop: "shop.myshopify.com",
|
|
34
|
+
state: "abc123",
|
|
35
|
+
isOnline: false,
|
|
36
|
+
scope: "read_products",
|
|
37
|
+
accessToken: "shpat_test",
|
|
38
|
+
expires,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const result = await storage.storeSession(session);
|
|
42
|
+
|
|
43
|
+
expect(result).toBe(true);
|
|
44
|
+
expect(client.mutation).toHaveBeenCalledWith(fns.storeSession, {
|
|
45
|
+
id: "offline_shop.myshopify.com",
|
|
46
|
+
shop: "shop.myshopify.com",
|
|
47
|
+
state: "abc123",
|
|
48
|
+
isOnline: false,
|
|
49
|
+
scope: "read_products",
|
|
50
|
+
accessToken: "shpat_test",
|
|
51
|
+
expires: "2025-06-01T00:00:00.000Z",
|
|
52
|
+
onlineAccessInfo: undefined,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("storeSession maps onlineAccessInfo correctly", async () => {
|
|
57
|
+
const client = createMockClient();
|
|
58
|
+
client.mutation.mockResolvedValue(null);
|
|
59
|
+
const storage = new ConvexSessionStorage(client, fns);
|
|
60
|
+
|
|
61
|
+
const session = new Session({
|
|
62
|
+
id: "online_shop.myshopify.com_1",
|
|
63
|
+
shop: "shop.myshopify.com",
|
|
64
|
+
state: "xyz",
|
|
65
|
+
isOnline: true,
|
|
66
|
+
onlineAccessInfo: {
|
|
67
|
+
expires_in: 86400,
|
|
68
|
+
associated_user_scope: "read_products",
|
|
69
|
+
associated_user: {
|
|
70
|
+
id: 123,
|
|
71
|
+
first_name: "John",
|
|
72
|
+
last_name: "Doe",
|
|
73
|
+
email: "john@example.com",
|
|
74
|
+
email_verified: true,
|
|
75
|
+
account_owner: true,
|
|
76
|
+
locale: "en",
|
|
77
|
+
collaborator: false,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
await storage.storeSession(session);
|
|
83
|
+
|
|
84
|
+
const args = client.mutation.mock.calls[0]![1];
|
|
85
|
+
expect(args.onlineAccessInfo).toEqual({
|
|
86
|
+
expires_in: 86400,
|
|
87
|
+
associated_user_scope: "read_products",
|
|
88
|
+
associated_user: {
|
|
89
|
+
id: 123,
|
|
90
|
+
first_name: "John",
|
|
91
|
+
last_name: "Doe",
|
|
92
|
+
email: "john@example.com",
|
|
93
|
+
email_verified: true,
|
|
94
|
+
account_owner: true,
|
|
95
|
+
locale: "en",
|
|
96
|
+
collaborator: false,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("loadSession converts ISO string to Date and returns Session instance", async () => {
|
|
102
|
+
const client = createMockClient();
|
|
103
|
+
const stored: ShopifySession = {
|
|
104
|
+
_id: "conv_abc",
|
|
105
|
+
_creationTime: 1234567890,
|
|
106
|
+
id: "offline_shop.myshopify.com",
|
|
107
|
+
shop: "shop.myshopify.com",
|
|
108
|
+
state: "abc123",
|
|
109
|
+
isOnline: false,
|
|
110
|
+
scope: "read_products",
|
|
111
|
+
accessToken: "shpat_test",
|
|
112
|
+
expires: "2025-06-01T00:00:00.000Z",
|
|
113
|
+
};
|
|
114
|
+
client.query.mockResolvedValue(stored);
|
|
115
|
+
const storage = new ConvexSessionStorage(client, fns);
|
|
116
|
+
|
|
117
|
+
const session = await storage.loadSession("offline_shop.myshopify.com");
|
|
118
|
+
|
|
119
|
+
expect(session).toBeInstanceOf(Session);
|
|
120
|
+
expect(session!.id).toBe("offline_shop.myshopify.com");
|
|
121
|
+
expect(session!.shop).toBe("shop.myshopify.com");
|
|
122
|
+
expect(session!.expires).toEqual(new Date("2025-06-01T00:00:00.000Z"));
|
|
123
|
+
expect(session!.accessToken).toBe("shpat_test");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("loadSession returns undefined for missing session", async () => {
|
|
127
|
+
const client = createMockClient();
|
|
128
|
+
client.query.mockResolvedValue(null);
|
|
129
|
+
const storage = new ConvexSessionStorage(client, fns);
|
|
130
|
+
|
|
131
|
+
const session = await storage.loadSession("nonexistent");
|
|
132
|
+
|
|
133
|
+
expect(session).toBeUndefined();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("loadSession defaults state to empty string", async () => {
|
|
137
|
+
const client = createMockClient();
|
|
138
|
+
const stored: ShopifySession = {
|
|
139
|
+
_id: "conv_abc",
|
|
140
|
+
_creationTime: 1234567890,
|
|
141
|
+
id: "test_id",
|
|
142
|
+
shop: "shop.myshopify.com",
|
|
143
|
+
isOnline: false,
|
|
144
|
+
// state is undefined
|
|
145
|
+
};
|
|
146
|
+
client.query.mockResolvedValue(stored);
|
|
147
|
+
const storage = new ConvexSessionStorage(client, fns);
|
|
148
|
+
|
|
149
|
+
const session = await storage.loadSession("test_id");
|
|
150
|
+
|
|
151
|
+
expect(session!.state).toBe("");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("deleteSession passes through correctly", async () => {
|
|
155
|
+
const client = createMockClient();
|
|
156
|
+
client.mutation.mockResolvedValue(true);
|
|
157
|
+
const storage = new ConvexSessionStorage(client, fns);
|
|
158
|
+
|
|
159
|
+
const result = await storage.deleteSession("offline_shop.myshopify.com");
|
|
160
|
+
|
|
161
|
+
expect(result).toBe(true);
|
|
162
|
+
expect(client.mutation).toHaveBeenCalledWith(fns.deleteSession, {
|
|
163
|
+
id: "offline_shop.myshopify.com",
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("deleteSessions passes through correctly", async () => {
|
|
168
|
+
const client = createMockClient();
|
|
169
|
+
client.mutation.mockResolvedValue(true);
|
|
170
|
+
const storage = new ConvexSessionStorage(client, fns);
|
|
171
|
+
|
|
172
|
+
const result = await storage.deleteSessions(["id1", "id2"]);
|
|
173
|
+
|
|
174
|
+
expect(result).toBe(true);
|
|
175
|
+
expect(client.mutation).toHaveBeenCalledWith(fns.deleteSessions, {
|
|
176
|
+
ids: ["id1", "id2"],
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("findSessionsByShop converts all results to Session instances", async () => {
|
|
181
|
+
const client = createMockClient();
|
|
182
|
+
const stored: ShopifySession[] = [
|
|
183
|
+
{
|
|
184
|
+
_id: "conv_1",
|
|
185
|
+
_creationTime: 1234567890,
|
|
186
|
+
id: "offline_shop.myshopify.com",
|
|
187
|
+
shop: "shop.myshopify.com",
|
|
188
|
+
isOnline: false,
|
|
189
|
+
scope: "read_products",
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
_id: "conv_2",
|
|
193
|
+
_creationTime: 1234567891,
|
|
194
|
+
id: "online_shop.myshopify.com_1",
|
|
195
|
+
shop: "shop.myshopify.com",
|
|
196
|
+
isOnline: true,
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
client.query.mockResolvedValue(stored);
|
|
200
|
+
const storage = new ConvexSessionStorage(client, fns);
|
|
201
|
+
|
|
202
|
+
const sessions = await storage.findSessionsByShop("shop.myshopify.com");
|
|
203
|
+
|
|
204
|
+
expect(sessions).toHaveLength(2);
|
|
205
|
+
expect(sessions[0]).toBeInstanceOf(Session);
|
|
206
|
+
expect(sessions[1]).toBeInstanceOf(Session);
|
|
207
|
+
expect(sessions[0]!.id).toBe("offline_shop.myshopify.com");
|
|
208
|
+
expect(sessions[1]!.id).toBe("online_shop.myshopify.com_1");
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Session } from "@shopify/shopify-api";
|
|
2
|
+
import type { SessionStorage } from "@shopify/shopify-app-session-storage";
|
|
3
|
+
import type { ShopifySession, ShopifySessionInput } from "./index.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Minimal client contract compatible with ConvexHttpClient, fetchQuery/fetchMutation wrappers,
|
|
7
|
+
* or any custom implementation.
|
|
8
|
+
*/
|
|
9
|
+
export interface ConvexSessionClient {
|
|
10
|
+
query<Output>(
|
|
11
|
+
name: string | { _returnType: Output },
|
|
12
|
+
args: Record<string, unknown>,
|
|
13
|
+
): Promise<Output>;
|
|
14
|
+
mutation<Output>(
|
|
15
|
+
name: string | { _returnType: Output },
|
|
16
|
+
args: Record<string, unknown>,
|
|
17
|
+
): Promise<Output>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* References to the consumer's public Convex functions that wrap the component's
|
|
22
|
+
* internal session CRUD operations.
|
|
23
|
+
*/
|
|
24
|
+
export interface SessionFunctionRefs {
|
|
25
|
+
storeSession: string | { _returnType: unknown; _args: unknown };
|
|
26
|
+
loadSession: string | { _returnType: unknown; _args: unknown };
|
|
27
|
+
deleteSession: string | { _returnType: unknown; _args: unknown };
|
|
28
|
+
deleteSessions: string | { _returnType: unknown; _args: unknown };
|
|
29
|
+
findSessionsByShop: string | { _returnType: unknown; _args: unknown };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function sessionToInput(session: Session): ShopifySessionInput {
|
|
33
|
+
return {
|
|
34
|
+
id: session.id,
|
|
35
|
+
shop: session.shop,
|
|
36
|
+
state: session.state,
|
|
37
|
+
isOnline: session.isOnline,
|
|
38
|
+
scope: session.scope,
|
|
39
|
+
expires: session.expires ? session.expires.toISOString() : undefined,
|
|
40
|
+
accessToken: session.accessToken,
|
|
41
|
+
onlineAccessInfo: session.onlineAccessInfo?.associated_user
|
|
42
|
+
? {
|
|
43
|
+
expires_in: session.onlineAccessInfo.expires_in,
|
|
44
|
+
associated_user_scope:
|
|
45
|
+
session.onlineAccessInfo.associated_user_scope,
|
|
46
|
+
associated_user: {
|
|
47
|
+
id: session.onlineAccessInfo.associated_user.id,
|
|
48
|
+
first_name: session.onlineAccessInfo.associated_user.first_name,
|
|
49
|
+
last_name: session.onlineAccessInfo.associated_user.last_name,
|
|
50
|
+
email: session.onlineAccessInfo.associated_user.email,
|
|
51
|
+
email_verified:
|
|
52
|
+
session.onlineAccessInfo.associated_user.email_verified,
|
|
53
|
+
account_owner:
|
|
54
|
+
session.onlineAccessInfo.associated_user.account_owner,
|
|
55
|
+
locale: session.onlineAccessInfo.associated_user.locale,
|
|
56
|
+
collaborator:
|
|
57
|
+
session.onlineAccessInfo.associated_user.collaborator,
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
: undefined,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function dataToSession(data: ShopifySession): Session {
|
|
65
|
+
return new Session({
|
|
66
|
+
id: data.id,
|
|
67
|
+
shop: data.shop,
|
|
68
|
+
state: data.state ?? "",
|
|
69
|
+
isOnline: data.isOnline,
|
|
70
|
+
scope: data.scope,
|
|
71
|
+
expires: data.expires ? new Date(data.expires) : undefined,
|
|
72
|
+
accessToken: data.accessToken,
|
|
73
|
+
onlineAccessInfo: data.onlineAccessInfo,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// TODO: Implement the ConvexSessionStorage class
|
|
78
|
+
// See the plan description above for guidance on the 5 required SessionStorage methods.
|
|
79
|
+
export class ConvexSessionStorage implements SessionStorage {
|
|
80
|
+
constructor(
|
|
81
|
+
private client: ConvexSessionClient,
|
|
82
|
+
private fns: SessionFunctionRefs,
|
|
83
|
+
) {}
|
|
84
|
+
|
|
85
|
+
async storeSession(session: Session): Promise<boolean> {
|
|
86
|
+
await this.client.mutation(this.fns.storeSession as string, sessionToInput(session));
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async loadSession(id: string): Promise<Session | undefined> {
|
|
91
|
+
const data = await this.client.query<ShopifySession | null>(
|
|
92
|
+
this.fns.loadSession as string,
|
|
93
|
+
{ id },
|
|
94
|
+
);
|
|
95
|
+
if (!data) return undefined;
|
|
96
|
+
return dataToSession(data);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async deleteSession(id: string): Promise<boolean> {
|
|
100
|
+
return await this.client.mutation<boolean>(
|
|
101
|
+
this.fns.deleteSession as string,
|
|
102
|
+
{ id },
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async deleteSessions(ids: string[]): Promise<boolean> {
|
|
107
|
+
return await this.client.mutation<boolean>(
|
|
108
|
+
this.fns.deleteSessions as string,
|
|
109
|
+
{ ids },
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async findSessionsByShop(shop: string): Promise<Session[]> {
|
|
114
|
+
const sessions = await this.client.query<ShopifySession[]>(
|
|
115
|
+
this.fns.findSessionsByShop as string,
|
|
116
|
+
{ shop },
|
|
117
|
+
);
|
|
118
|
+
return sessions.map(dataToSession);
|
|
119
|
+
}
|
|
120
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|