@devvit/public-api 0.11.0-next-2024-08-19-689d51fc5.0 → 0.11.0-next-2024-08-20-4ebb1a01f.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"ui-request-handler.d.ts","sourceRoot":"","sources":["../../../src/devvit/internals/ui-request-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,QAAQ,EAAoB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAwB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAgB7D,wBAAgB,WAAW,CACzB,SAAS,EAAE,GAAG,CAAC,iBAAiB,GAC/B,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,UAAU,CAAC,CAK7D;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAK9D"}
1
+ {"version":3,"file":"ui-request-handler.d.ts","sourceRoot":"","sources":["../../../src/devvit/internals/ui-request-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,QAAQ,EAAoB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAwB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAqB7D,wBAAgB,WAAW,CACzB,SAAS,EAAE,GAAG,CAAC,iBAAiB,GAC/B,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,UAAU,CAAC,CAW7D;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAK9D"}
@@ -2,6 +2,7 @@ import { CustomPostDefinition, UIResponse } from '@devvit/protos';
2
2
  import { Devvit } from '../Devvit.js';
3
3
  import { BlocksHandler } from './blocks/handler/BlocksHandler.js';
4
4
  import { extendDevvitPrototype } from './helpers/extendDevvitPrototype.js';
5
+ import { makeUpgradeAppComponent, parseDevvitUserAgent, shouldShowUpgradeAppScreen, } from './upgrade-app-shim.js';
5
6
  /**
6
7
  * Extend me to add new surfaces to Devvit.
7
8
  */
@@ -14,6 +15,11 @@ const UIComponentBindings = [
14
15
  ];
15
16
  export function makeHandler(component) {
16
17
  return async (req, metadata) => {
18
+ const parsedUserAgent = parseDevvitUserAgent(metadata['devvit-user-agent']?.values?.[0] ?? '');
19
+ if (parsedUserAgent && shouldShowUpgradeAppScreen(parsedUserAgent)) {
20
+ const handler = new BlocksHandler(makeUpgradeAppComponent(parsedUserAgent.platform));
21
+ return UIResponse.fromJSON(await handler.handle(req, metadata));
22
+ }
17
23
  const handler = new BlocksHandler(component);
18
24
  return UIResponse.fromJSON(await handler.handle(req, metadata));
19
25
  };
@@ -0,0 +1,29 @@
1
+ /** @jsx Devvit.createElement */
2
+ /** @jsxFrag Devvit.Fragment */
3
+ import { Devvit } from '../Devvit.js';
4
+ export type ParsedDevvitUserAgent = {
5
+ company: 'Reddit';
6
+ platform: 'iOS';
7
+ rawVersion: string;
8
+ versionNumber: number;
9
+ } | {
10
+ company: 'Reddit';
11
+ platform: 'Android';
12
+ rawVersion: string;
13
+ versionNumber: number;
14
+ } | {
15
+ company: 'Reddit';
16
+ platform: 'Shreddit';
17
+ rawVersion: string;
18
+ } | {
19
+ company: 'Reddit';
20
+ platform: 'Play';
21
+ rawVersion: string;
22
+ };
23
+ export declare const parseDevvitUserAgent: (input: string) => ParsedDevvitUserAgent | undefined;
24
+ export declare const shouldShowUpgradeAppScreen: (parsedDevvitUserAgent: ParsedDevvitUserAgent | undefined) => boolean;
25
+ export declare const UpgradeAppComponent: Devvit.BlockComponent<{
26
+ platform: ParsedDevvitUserAgent['platform'];
27
+ }>;
28
+ export declare const makeUpgradeAppComponent: (platform: ParsedDevvitUserAgent['platform']) => () => JSX.Element;
29
+ //# sourceMappingURL=upgrade-app-shim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-app-shim.d.ts","sourceRoot":"","sources":["../../../src/devvit/internals/upgrade-app-shim.tsx"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,+BAA+B;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,MAAM,qBAAqB,GAC7B;IACE,OAAO,EAAE,QAAQ,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB,GACD;IACE,OAAO,EAAE,QAAQ,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB,GACD;IACE,OAAO,EAAE,QAAQ,CAAC;IAClB,QAAQ,EAAE,UAAU,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB,GACD;IACE,OAAO,EAAE,QAAQ,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAON,eAAO,MAAM,oBAAoB,UAAW,MAAM,KAAG,qBAAqB,GAAG,SA8D5E,CAAC;AAEF,eAAO,MAAM,0BAA0B,0BACd,qBAAqB,GAAG,SAAS,KACvD,OAmBF,CAAC;AAkBF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,cAAc,CAAC;IACtD,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC,CAAC;CAC7C,CA8BA,CAAC;AAKF,eAAO,MAAM,uBAAuB,aAAc,qBAAqB,CAAC,UAAU,CAAC,sBAElF,CAAC"}
@@ -0,0 +1,109 @@
1
+ /** @jsx Devvit.createElement */
2
+ /** @jsxFrag Devvit.Fragment */
3
+ import { Devvit } from '../Devvit.js';
4
+ const getVersionNumberFromRawVersion = (rawVersion) => {
5
+ const versionNumber = Number(rawVersion.trim().split('.').pop());
6
+ return isNaN(versionNumber) ? undefined : versionNumber;
7
+ };
8
+ export const parseDevvitUserAgent = (input) => {
9
+ const [company, platform, rawVersion] = input.trim().split(';');
10
+ if (!company || !platform || !rawVersion) {
11
+ console.warn(`Received a malformed devvit-user-agent! Received: '${input}'`);
12
+ return;
13
+ }
14
+ if (company !== 'Reddit') {
15
+ console.warn(`Received unknown company name in user agent! Received: '${input}'`);
16
+ return;
17
+ }
18
+ if (platform === 'iOS') {
19
+ const versionNumber = getVersionNumberFromRawVersion(rawVersion);
20
+ if (versionNumber === undefined) {
21
+ console.warn(`Could not parse version number from user agent! Received: '${input}'`);
22
+ return;
23
+ }
24
+ return {
25
+ company: 'Reddit',
26
+ platform: 'iOS',
27
+ rawVersion,
28
+ versionNumber,
29
+ };
30
+ }
31
+ if (platform === 'Android') {
32
+ const versionNumber = getVersionNumberFromRawVersion(rawVersion);
33
+ if (versionNumber === undefined) {
34
+ console.warn(`Could not parse version number from user agent! Received: '${input}'`);
35
+ return;
36
+ }
37
+ return {
38
+ company: 'Reddit',
39
+ platform: 'Android',
40
+ rawVersion,
41
+ versionNumber,
42
+ };
43
+ }
44
+ if (platform === 'Shreddit') {
45
+ return {
46
+ company: 'Reddit',
47
+ platform: 'Shreddit',
48
+ rawVersion,
49
+ };
50
+ }
51
+ if (platform === 'Play') {
52
+ return {
53
+ company: 'Reddit',
54
+ platform: 'Play',
55
+ rawVersion,
56
+ };
57
+ }
58
+ console.warn(`Received unknown platform:`, platform);
59
+ };
60
+ export const shouldShowUpgradeAppScreen = (parsedDevvitUserAgent) => {
61
+ // If we couldn't parse, default to trying to render the app
62
+ if (!parsedDevvitUserAgent) {
63
+ console.warn(`Could not parse devvit-user-agent! Received: '${JSON.stringify(parsedDevvitUserAgent)}'`);
64
+ return false;
65
+ }
66
+ if (parsedDevvitUserAgent.platform === 'Android') {
67
+ return parsedDevvitUserAgent.versionNumber < 1819908;
68
+ }
69
+ if (parsedDevvitUserAgent.platform === 'iOS') {
70
+ return parsedDevvitUserAgent.versionNumber < 614940;
71
+ }
72
+ // Default to trying to render since we couldn't explicitly get the version number
73
+ return false;
74
+ };
75
+ const getUpgradeLinkForPlatform = (platform) => {
76
+ switch (platform) {
77
+ case 'Android':
78
+ return 'https://play.google.com/store/apps/details?id=com.reddit.frontpage';
79
+ case 'iOS':
80
+ return 'https://apps.apple.com/us/app/reddit/id1064216828';
81
+ case 'Play':
82
+ case 'Shreddit':
83
+ break;
84
+ default:
85
+ console.error(`No upgrade link for platform: ${platform}`);
86
+ }
87
+ };
88
+ export const UpgradeAppComponent = ({ platform }, context) => {
89
+ return (Devvit.createElement("blocks", null,
90
+ Devvit.createElement("vstack", { alignment: "middle center", height: 100, width: 100 },
91
+ Devvit.createElement("vstack", { maxWidth: '300px', gap: "large", alignment: "middle center" },
92
+ Devvit.createElement("vstack", { gap: "medium", alignment: "middle center" },
93
+ Devvit.createElement("image", { imageHeight: 100, imageWidth: 100, url: "https://i.redd.it/p1vmc5ulmpib1.png" }),
94
+ Devvit.createElement("text", { size: "large", weight: "bold", wrap: true, alignment: "center" }, "Uh oh, the app you're trying to use requires the latest version of Reddit. Please upgrade your app to continue.")),
95
+ Devvit.createElement("hstack", { alignment: "middle center" },
96
+ Devvit.createElement("button", { onPress: () => {
97
+ const upgradeLink = getUpgradeLinkForPlatform(platform);
98
+ if (upgradeLink) {
99
+ context.ui.navigateTo(upgradeLink);
100
+ }
101
+ else {
102
+ console.warn(`No upgrade link found for platform:`, platform);
103
+ }
104
+ } }, "Upgrade"))))));
105
+ };
106
+ // A builder to make a component so that we don't have to rename `ui-request.handler.ts` to `.tsx`
107
+ // Not that there's really anything wrong with that, but I like the separation of concerns since
108
+ // we also has to set the pragma at the top of files that use Devvit-y stuff
109
+ export const makeUpgradeAppComponent = (platform) => () => (Devvit.createElement(UpgradeAppComponent, { platform: platform }));
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-app-shim.test.d.ts","sourceRoot":"","sources":["../../../src/devvit/internals/upgrade-app-shim.test.ts"],"names":[],"mappings":""}
package/meta.json CHANGED
@@ -12544,8 +12544,19 @@
12544
12544
  ],
12545
12545
  "format": "esm"
12546
12546
  },
12547
+ "src/devvit/internals/upgrade-app-shim.tsx": {
12548
+ "bytes": 5078,
12549
+ "imports": [
12550
+ {
12551
+ "path": "src/devvit/Devvit.ts",
12552
+ "kind": "import-statement",
12553
+ "original": "../Devvit.js"
12554
+ }
12555
+ ],
12556
+ "format": "esm"
12557
+ },
12547
12558
  "src/devvit/internals/ui-request-handler.ts": {
12548
- "bytes": 1280,
12559
+ "bytes": 1746,
12549
12560
  "imports": [
12550
12561
  {
12551
12562
  "path": "../protos/dist/index.js",
@@ -12566,6 +12577,11 @@
12566
12577
  "path": "src/devvit/internals/helpers/extendDevvitPrototype.ts",
12567
12578
  "kind": "import-statement",
12568
12579
  "original": "./helpers/extendDevvitPrototype.js"
12580
+ },
12581
+ {
12582
+ "path": "src/devvit/internals/upgrade-app-shim.tsx",
12583
+ "kind": "import-statement",
12584
+ "original": "./upgrade-app-shim.js"
12569
12585
  }
12570
12586
  ],
12571
12587
  "format": "esm"
@@ -14448,8 +14464,11 @@
14448
14464
  "src/devvit/internals/blocks/handler/BlocksHandler.ts": {
14449
14465
  "bytesInOutput": 14957
14450
14466
  },
14467
+ "src/devvit/internals/upgrade-app-shim.tsx": {
14468
+ "bytesInOutput": 4017
14469
+ },
14451
14470
  "src/devvit/internals/ui-request-handler.ts": {
14452
- "bytesInOutput": 645
14471
+ "bytesInOutput": 1000
14453
14472
  },
14454
14473
  "src/devvit/Devvit.ts": {
14455
14474
  "bytesInOutput": 18680
@@ -14530,7 +14549,7 @@
14530
14549
  "bytesInOutput": 370
14531
14550
  }
14532
14551
  },
14533
- "bytes": 14860165
14552
+ "bytes": 14875397
14534
14553
  }
14535
14554
  }
14536
14555
  }
package/meta.min.json CHANGED
@@ -3873,8 +3873,19 @@
3873
3873
  ],
3874
3874
  "format": "esm"
3875
3875
  },
3876
+ "src/devvit/internals/upgrade-app-shim.tsx": {
3877
+ "bytes": 5078,
3878
+ "imports": [
3879
+ {
3880
+ "path": "src/devvit/Devvit.ts",
3881
+ "kind": "import-statement",
3882
+ "original": "../Devvit.js"
3883
+ }
3884
+ ],
3885
+ "format": "esm"
3886
+ },
3876
3887
  "src/devvit/internals/ui-request-handler.ts": {
3877
- "bytes": 1280,
3888
+ "bytes": 1746,
3878
3889
  "imports": [
3879
3890
  {
3880
3891
  "path": "@devvit/protos",
@@ -3895,6 +3906,11 @@
3895
3906
  "path": "src/devvit/internals/helpers/extendDevvitPrototype.ts",
3896
3907
  "kind": "import-statement",
3897
3908
  "original": "./helpers/extendDevvitPrototype.js"
3909
+ },
3910
+ {
3911
+ "path": "src/devvit/internals/upgrade-app-shim.tsx",
3912
+ "kind": "import-statement",
3913
+ "original": "./upgrade-app-shim.js"
3898
3914
  }
3899
3915
  ],
3900
3916
  "format": "esm"
@@ -4738,7 +4754,7 @@
4738
4754
  "imports": [],
4739
4755
  "exports": [],
4740
4756
  "inputs": {},
4741
- "bytes": 1206177
4757
+ "bytes": 1214341
4742
4758
  },
4743
4759
  "dist/public-api.min.js": {
4744
4760
  "imports": [
@@ -5430,7 +5446,7 @@
5430
5446
  "bytesInOutput": 1418
5431
5447
  },
5432
5448
  "src/devvit/internals/ui-request-handler.ts": {
5433
- "bytesInOutput": 313
5449
+ "bytesInOutput": 445
5434
5450
  },
5435
5451
  "src/devvit/internals/blocks/handler/UIClient.ts": {
5436
5452
  "bytesInOutput": 967
@@ -5474,6 +5490,9 @@
5474
5490
  "src/devvit/internals/blocks/handler/BlocksHandler.ts": {
5475
5491
  "bytesInOutput": 6864
5476
5492
  },
5493
+ "src/devvit/internals/upgrade-app-shim.tsx": {
5494
+ "bytesInOutput": 2170
5495
+ },
5477
5496
  "src/apis/reddit/helpers/makeGettersEnumerable.ts": {
5478
5497
  "bytesInOutput": 166
5479
5498
  },
@@ -5550,7 +5569,7 @@
5550
5569
  "bytesInOutput": 178
5551
5570
  }
5552
5571
  },
5553
- "bytes": 258242
5572
+ "bytes": 260544
5554
5573
  }
5555
5574
  }
5556
5575
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/public-api",
3
- "version": "0.11.0-next-2024-08-19-689d51fc5.0",
3
+ "version": "0.11.0-next-2024-08-20-4ebb1a01f.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "types": "./index.d.ts",
32
32
  "dependencies": {
33
- "@devvit/protos": "0.11.0-next-2024-08-19-689d51fc5.0",
34
- "@devvit/shared-types": "0.11.0-next-2024-08-19-689d51fc5.0",
33
+ "@devvit/protos": "0.11.0-next-2024-08-20-4ebb1a01f.0",
34
+ "@devvit/shared-types": "0.11.0-next-2024-08-20-4ebb1a01f.0",
35
35
  "base64-js": "1.5.1",
36
36
  "clone-deep": "4.0.1",
37
37
  "core-js": "3.27.2",
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@ampproject/filesize": "4.3.0",
42
- "@devvit/eslint-config": "0.11.0-next-2024-08-19-689d51fc5.0",
43
- "@devvit/repo-tools": "0.11.0-next-2024-08-19-689d51fc5.0",
44
- "@devvit/tsconfig": "0.11.0-next-2024-08-19-689d51fc5.0",
42
+ "@devvit/eslint-config": "0.11.0-next-2024-08-20-4ebb1a01f.0",
43
+ "@devvit/repo-tools": "0.11.0-next-2024-08-20-4ebb1a01f.0",
44
+ "@devvit/tsconfig": "0.11.0-next-2024-08-20-4ebb1a01f.0",
45
45
  "@microsoft/api-extractor": "7.41.0",
46
46
  "@reddit/faceplate-ui": "16.1.0",
47
47
  "@types/clone-deep": "4.0.1",
@@ -64,5 +64,5 @@
64
64
  }
65
65
  },
66
66
  "source": "./src/index.ts",
67
- "gitHead": "4e0d11bcefd0c44ce4a4b01a22525ebc4edc51dd"
67
+ "gitHead": "5fc4461855bfebaafcbfefd06e09d8fb93dd2bb3"
68
68
  }